【发布时间】:2013-12-25 22:25:11
【问题描述】:
抱歉,这措辞不好,但很难描述。
我想我会直接跳到例子:
add :: Integer -> Integer -> Integer
add x y = x + y
为什么会这样:
:: Integer -> Integer -> Integer
代替:
:: Integer, Integer -> Integer
箭头是“Function type-mapping operator”,不是某种分隔符,不是吗?
【问题讨论】:
-
这里的答案可能不清楚,但也请注意
(->)只是一个带有两个参数的常规类型(尽管具有特殊的语法和隐藏的实现)。启动 ghci 并运行:info (->);您会看到在 Prelude 中甚至已经为((->) a)定义了一些类型类实例 -
请注意,Clean 是一种非常类似于 Haskell 的语言,您可以省略一些箭头。所以你可以为
Int -> Int -> Int写Int Int -> Int,或者甚至(对我来说不可读)(a b -> c) [a] [b] -> [c])为((a -> b -> c) -> [a] -> [b] -> [c])。解释似乎是subtly different from the one found in Haskell。如果我理解它能够表达一些我们在 Haskell 中无法做出的区别。