问题描述
在这里,认为,无结构类型不是函数。然而,例如在中描述点免费功能时,他们在定义中没有明确的参数,并且它看起来更像是一种咖啡的属性。具体来说: f = map 和 f => ID 。地图在这种情况下有所不同?如 f = map 只是一个绑定到一个恰好是 f 的函数的简单的返回 map (类似于 f = 2 返回 2 )然后接受参数。但 f = id。 map 被称为函数,因为它是免费的。 False 不是函数。这很明显;如果你考虑所有可能的值并删除那些具有函数类型的值,那么剩下的就是...不是函数。
这完全与
考虑以下函数定义:
map1,map2,map3,map4 ::(a - > b) - > [a] - > [b]
map1 =地图
map2 = id。地图
map3 f =地图f
map4 _ [] = []
map4 f(x:xs)= fx:map4 f xs
这些都是相同函数的所有定义(并且有无限多种方法来定义相当于 map 函数)。 map1 显然是一个无点定义; map4 显然不是。它们都明显具有函数类型(同一个!),那么我们怎么能说无点定义不是函数呢?只有当我们将函数的定义改为Haskell程序员通常的意思(即函数是 x - > y 类型的东西)时,对于一些 x 和 y ;在这种情况下,我们使用 a - > b 为 x 和 [a] - > [b] for <$ c $ )。
map3 的定义是免费(减少点?);该定义将其第一个参数命名为 f ,但没有提及第二个参数。
是无点性是定义的质量,而是功能是值的属性。无点函数的概念实际上并不合理,因为给定的函数可以通过多种方式定义(其中一些是无点的,另一些则不是)。每当你看到有人在谈论一个免费的功能时,他们的意思就是一个无点的定义。
你似乎担心 map1 = map 不是一个函数,因为它只是对现有值 map 的绑定,就像 x = 2 。你在这里混淆概念。请记住,函数在Haskell中是一流的; 作为功能的东西是作为价值的东西的子集,而不是一类不同的东西!因此,当 map 是现有值是一个函数时,则是 map1 = map 只是将新名称绑定到现有值。 也定义函数 map1 ;这两者不是相互排斥的。
您通过查看代码来回答这是免费的问题。函数的定义。您通过查看类型来回答这是一个函数的问题。
Conal here argues that nullary-constructed types are not functions. However, point-free functions are described as such for example on Wikipedia, when they take no explicit arguments in their definitions, and it seemingly is rather a property of currying. How exactly are they functions?
Specifically: how are f = map and f = id . map different in this context? As in, f = map is simply just a binding to a value that happens to be a function where f simply "returns" map (similar to how f = 2 "returns" 2) which then takes the arguments. But f = id . map is referred to as a function because it's point-free.
Conal's blog post boils down to saying "non-functions are not functions", e.g. False is not a function. This is pretty obvious; if you consider all possible values and remove the ones which have a function type, then those that remain are... not functions.
That has absolutely nothing to do with the notion of point-free definitions.
Consider the following function definitions:
map1, map2, map3, map4 :: (a -> b) -> [a] -> [b] map1 = map map2 = id . map map3 f = map f map4 _ [] = [] map4 f (x:xs) = f x : map4 f xs
These are all definitions of the same function (and there are infinitely many more ways to define something equivalent to the map function). map1 is obviously a point-free definition; map4 is obviously not. They also both obviously have a function type (the same one!), so how can we say that point-free definitions are not functions? Only if we change our definition of "function" to something else than what is usually meant by Haskell programmers (which is that a function is something of type x -> y, for some x and y; in this case we're using a -> b as x and [a] -> [b] for y).
And the definition of map3 is "partially point-free" (point-reduced?); the definition names its first argument f, but doesn't mention the second argument.
The point in all this is that "point-free-ness" is a quality of definitions, while "being a function" is a property of values. The notion of point-free function doesn't actually make sense, since a given function can be defined many ways (some of them point-free, others not). Whenever you see someone talking about a point-free function, they mean a point-free definition.
You seem to be concerned that map1 = map isn't a function because it's just a binding to the existing value map, just like x = 2. You're confusing notions here. Remember that functions are first-class in Haskell; "things that are functions" is a subset of "things that are values", not a different class of thing! So when map is an existing value which is a function, then yes map1 = map is just binding a new name to an existing value. It's also defining the function map1; the two are not mutually exclusive.
You answer the question "is this point-free" by looking at code; the definition of a function. You answer the question "is this a function" by looking at types.
这篇关于点函数实际上如何“函数”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!