Map是具有两个参数的函数吗? [英] Is Map a function with Two Arguments?
问题描述
我正在尝试解决一个选择题,指出以下内容
I'm trying to solve a multiple choice question that states the following
- 地图是一个重载函数
- map是一个多态函数
- 地图是咖喱函数
- 地图是高阶函数
- map是具有两个参数的函数
我知道地图过载,多态,咖喱和高阶.这是否意味着map是仅具有单个参数的函数?(我意识到这是函数被咖喱化的结果,并且haskell仅具有带单参数的函数,并通过currying和partial application来应用多个参数函数)
I know that map is overloaded, polymorphic, curried and higher-order. Does that mean that map is a function with just a single argument ? (I realize that this is a consequence of a function being curried, and haskell only has functions with single arguments with multiple argument functions being applied through currying and partial application)
推理正确吗?如果是这样,则map函数如何通过部分应用程序评估函数?
Is the reasoning correct ? And if so, how does the map function evaluate a function through partial application ?
推荐答案
与所有Haskell函数一样, map
是单参数函数.让我们看一下它的类型签名:
Like all Haskell functions, map
is a single-argument function. Let's have a look at its type signature:
map :: (a -> b) -> [a] -> [b]
等效于:
map :: (a -> b) -> ([a] -> [b])
我认为这种签名在您的情况下更容易理解: map
获得一个参数-从 a
到 b
的函数-并返回另一个功能,这次是从 [a]
到 [b]
.
I think this signature is easier to understand in your case: map
gets one argument - a function from a
to b
- and returns another function, this time from [a]
to [b]
.
本质, map
提升"一个功能-它需要一个常规功能并提升"它,以便它可以在列表上使用.提升的想法出现在Haskell的多个地方.
Essentialy, map
"lifts" a function - it takes a regular function and "lifts" it so it'll work on lists. This idea of lifting appears in several places in Haskell.
例如, even
是从 Int
到 Bool
的函数-它需要一个数字并在为偶数时返回true.而且 map even
是从 [Int]
到 [Bool]
的函数-它接受一个数字列表并返回一个布尔值列表. map even
只是 even
在不同的上下文"中工作-列表而不是单个值.
For example, even
is a function from Int
to Bool
- it takes a number and returns true iff it is even. And map even
is a function from [Int]
to [Bool]
- it takes a list of numbers and returns a list of boolean values. map even
is just even
working in a different "context" - lists instead of single values.
这篇关于Map是具有两个参数的函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!