I am following along with the Learn you a Haskell for great good, I have implemented take'
:
take' :: (Ord i, Num i) => i -> [a] -> [a]
take' n _
| n <= 0 = []
take' _ [] = []
take' n (x:xs) = x: take' (n-1) xs
When testing the function with:
take' -2 [2]
instead of getting an empty list, I have this message:
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 t.
(Num i, Num t, Num (i -> [a] -> [a]), Num ([t] -> i -> [a] -> [a]),
Ord i) =>
i -> [a] -> [a]
I have added a space between -
and 2
as suggested, and it leads to the same error:
*Main> take' - 2 [2]
<interactive>:78:1:
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 t.
(Num i, Num t, Num (i -> [a] -> [a]), Num ([t] -> i -> [a] -> [a]),
Ord i) =>
i -> [a] -> [a]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…