【发布时间】:2016-01-12 15:01:25
【问题描述】:
我刚刚开始阅读《Learn You a Haskell for Great Good》。在第 3 章中,我看到作者使用 =>,但我无法确切了解它的作用以及他们使用它的原因。
我认为这是第一次使用它:
lucky :: (Integral a) => a -> String
lucky 7 = "LUCKY NUMBER SEVEN!"
lucky x = "Sorry, you're out of luck, pal!"
这是另一个例子:
tell :: (Show a) => [a] -> String
tell [] = "The list is empty"
tell (x:[]) = "The list has one element: " ++ show x
tell (x:y:[]) = "The list has two elements: " ++ show x ++ " and " ++ show y
tell (x:y:_) = "This list is long. The first two elements are: " ++ show x ++ " and " ++ show y
谢谢。
【问题讨论】:
-
由于某种原因,即使我使用了类似的措辞,我也找不到该链接。
-
@DxAlpha:别担心。您的问题仍在增加价值,因为下一个寻找
=>的人可能会找到它。重复不一定是坏事。
标签: haskell