[1,2,3]
is a List Int
,只能与整数列表一起使用的函数必须具有List Int
在他们的类型签名中。["a", "b"]
is a List String
,只能使用字符串列表的函数必须具有List String
在他们的类型签名中。适用于任何类型列表的函数(例如List.length
)可以有一个通用类型签名(例如List a
or List b
)。的含义a
仅在类型签名中相关。例如一个类型为的函数List a -> a
,当给定一个List Int
会返回一个Int
。当给定一个List String
它会返回一个String
.
以map http://package.elm-lang.org/packages/elm-lang/core/2.1.0/List#map函数的签名为(a -> b) -> List a -> List b
。它说给定一个需要一个函数a
并返回一个b
, and a List a
,它将返回一个List b
.
给定一个函数,它需要一个String
并返回一个Int
, and a List String
, map
将返回一个List Int
.
List.map String.length ["a", "aa", "aaa"]
-- [1, 2, 3] : List Int
给定一个函数,它需要一个Int
并返回一个String
, and a List Int
, map
将返回一个List String
.
List.map (\n -> String.repeat n "a") [1, 2, 3]
-- ["a", "aa", "aaa"] : List String