简体   繁体   English

类型声明[[Integer] - > Integer]

[英]Type declaration [[Integer] -> Integer]

I'm learning haskell and saw function compositions. 我正在学习haskell并看到了函数组合。 Tried to composite map and foldl 尝试复合mapfoldl

mapd = (map.foldl)

Than

test = (mapd (\x y -> x + y ) [1,2,3,4])

Type of test is 测试类型是

test :: [[Integer] -> Integer]

So what is this type declaration means? 那么这种类型的声明是什么意思呢?

That means that your function "test" returns a list of functions. 这意味着您的函数“test”返回一个函数列表。 And that each of those functions takes a list of integers and returns an integer. 并且每个函数都采用整数列表并返回一个整数。

test 
= mapd (\x y -> x + y ) [1,2,3,4]
= mapd (+) [1,2,3,4]
= (map . foldl) (+) [1,2,3,4]
= map (foldl (+)) [1,2,3,4]
= [ foldl (+) 1
  , foldl (+) 2
  , foldl (+) 3
  , foldl (+) 4 ]

The result is a list of functions. 结果是一系列功能。 The first function takes a list of integers, and sums it up starting from 1 . 第一个函数采用整数列表,并从1开始对其求和。 The second is similar, but starts from 2 . 第二个是类似的,但从2开始。 And so on for the remaining functions. 等等剩下的功能。

As fgv already stated, this is a list of functions from list of integers to integer, hence the [[Integer] -> Integer] type. 正如fgv已经说过的,这是从整数列表到整数的函数列表,因此是[[Integer] -> Integer]类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM