haskell - Haskell 中类型的含义是什么

标签 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)

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

我可以做一些解释,我将非常感谢任何帮助。

最佳答案

ranPosition i d 的类型是 [Point] -(柯里化(Currying)为您提供一个返回 [Point] 的函数)

getBlockSums i d 的类型为 [Point] -> [BlockSum] -(柯里化(Currying)为您提供一个从 [Point]< 返回函数的函数[BlockSum])

关于haskell - Haskell 中类型的含义是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5581523/

相关文章:

c++ - 为什么删除重载时需要使用声明

haskell - '#' 是什么意思?

haskell - Haskell 中的亚型多态性

haskell - 为什么图书馆设计者在 Text 似乎合适的地方使用 ByteString?

function - Dart - 将函数声明为变量

c++ - 使用多个头文件和 cpp 文件帮助

haskell - 如何在 `type`关键字中使用typeclass?

mysql - 大型 MySQL 数据库如何变得高效?

artificial-intelligence - 多数独AI方法

algorithm - 最被低估或鲜为人知但有用的算法是什么?