Haskell 中类型的含义是什么

发布于 2024-10-31 03:43:44 字数 641 浏览 0 评论 0原文

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

对于下面的类型声明:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紅太極 2024-11-07 03:43:44

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])

故事还在继续 2024-11-07 03:43:44

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

以下表达式的类型:

foo 
foo a
foo a b

必须全部不同,这不是很明显吗?如果您不清楚,请返回并阅读函数应用。

Sure, but they asked for the types of expressions, not functions.

Is it not obvious that the type of the following expressions:

foo 
foo a
foo a b

must all be different? If this is not clear to you, then go back and read about function application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文