类型在haskell中意味着什么

时间:2011-04-07 13:03:28

标签: haskell theory function-declaration type-declaration

我在课堂上被问到这个问题让我很困惑,我们得到了以下内容:

对于波纹管类型声明:

ranPositions :: Image -> Dims -> [Point] 
getBlockSums :: Image -> Dims -> [Point] -> [BlockSum]
i :: Image
d :: Dims

以下哪些类型? 不是上面的那个吗?!

ranPositions i d
getBlockSums i d

所以我回答的是:

type ranPositions = Array Point Int, (Int, Int)
type getBlockSums = Array Point Int, (Int, Int)

// Because (this was given)

type Image = Array Point Int 
type Dims = (Int, Int)

除了错误之外,这个问题让我困惑,因为我认为函数的类型是在::之后声明的,因此它已经被赋予了,不是吗?

我可以做一些解释,我真的很感激任何帮助。

2 个答案:

答案 0 :(得分:8)

ranPosition i d的类型为[Point] - (currying为您提供了一个返回[Point]的函数)

getBlockSums i d的类型为[Point] -> [BlockSum] - (currying为您提供了一个函数,可以将函数从[Point]返回到[BlockSum]

答案 1 :(得分:3)

当然,但是他们要求表达式的类型,而不是函数

以下表达式的类型不明显:

foo 
foo a
foo a b

一定都不一样吗?如果您不清楚这一点,请返回并阅读有关功能应用程序的信息。

相关问题