Haskell中的类型推断有一点学习曲线(至少可以说!).开始学习它的一个好方法是使用简单的例子.因此,以下是类型推断的"hello world".
请考虑以下示例:
Prelude> :t 3
3 :: (Num t) => t
Prelude> let x = 3
Prelude> :t x
x :: Integer
Run Code Online (Sandbox Code Playgroud)
问题是:为什么3和x有不同的类型?
链接摘要:
阅读以下答案的完整故事; 这里只是一个链接摘要: