Haskell 中类型的含义是什么
我在课堂上被问到这个问题,这让我很困惑,我们得到了以下内容:
对于下面的类型声明:
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)
除了错误之外,这个问题还让我困惑,因为我认为函数的类型是在 :: 之后声明的类型。
因此它已经被给出了,不是吗?
我可以做一些解释,我将非常感谢任何帮助。
I got asked this question in a class that left me pretty confused, we were presented with the following:
For the bellow type declarations:
ranPositions :: Image -> Dims -> [Point]
getBlockSums :: Image -> Dims -> [Point] -> [BlockSum]
i :: Image
d :: Dims
What are the types of the following ? isn't it the above?!
ranPositions i d
getBlockSums i d
So what I responded was this:
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)
Apart from being wrong, this question confused me because i thought the type of a function was what was declared after the ::
and therefore it had been already given, no?
I could do with a bit of explaining and I will really appreciate any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ranPosition i d
的类型是[Point]
- (柯里化为您提供一个返回[Point]
的函数)getBlockSums 的类型i d
是[Point] -> [BlockSum]
-(柯里化为您提供了一个函数,该函数返回从[Point]
到[BlockSum]
的函数)The type of
ranPosition i d
is[Point]
- (currying gives you a function that returns[Point]
)The type of
getBlockSums i d
is[Point] -> [BlockSum]
- (currying gives you a function that returns a function from[Point]
to[BlockSum]
)当然可以,但他们要求的是表达式的类型,而不是函数。
以下表达式的类型:
必须全部不同,这不是很明显吗?如果您不清楚,请返回并阅读函数应用。
Sure, but they asked for the types of expressions, not functions.
Is it not obvious that the type of the following expressions:
must all be different? If this is not clear to you, then go back and read about function application.