我正在关注Learn you a Haskell for great good,我已经实施了take'
:
take' :: (Ord i, Num i) => i -> [a] -> [a]
take' n _
| n <= 0 = []
take' _ [] = []
take' n (x:xs) = x: take' (n-1) xs
Run Code Online (Sandbox Code Playgroud)
测试功能时:
take' -2 [2]
Run Code Online (Sandbox Code Playgroud)
而不是得到一个空列表,我有这样的消息:
Non type-variable argument in the constraint: Num (i -> [a] -> [a])
(Use FlexibleContexts to permit this)
When checking that ‘it’ has the inferred type
it :: forall i a …
Run Code Online (Sandbox Code Playgroud) 我有以下操作:
Prelude> mod (3 - 12) 7
Run Code Online (Sandbox Code Playgroud)
结果我有5个.
为什么结果是5?
当我尝试这样的事情时:
Prelude> mod -9 7
Run Code Online (Sandbox Code Playgroud)
然后我有错误:
<interactive>:6:1: error:
• Non type-variable argument
in the constraint: Num (t -> a -> a -> a)
(Use FlexibleContexts to permit this)
• When checking the inferred type
it :: forall a t.
(Num (t -> a -> a -> a), Num (a -> a -> a), Num t, Integral a) =>
a -> a -> a
Run Code Online (Sandbox Code Playgroud)
为什么?
我忘了提,我刚开始学习哈斯克尔.