1
我是Haskell的新手。我自己實施drop
。在Haskell中檢查推斷類型時的非類型變量參數
myDrop n xs = if n <= 0 || null xs
then xs
else myDrop (n - 1) (tail xs)
但我把它當n < 0
,例如myDrop -2 [1, 2, 3]
。它會引發錯誤:
<interactive>:23:1: error:
• Non type-variable argument
in the constraint: Num ([t] -> t1 -> [a] -> [a])
(Use FlexibleContexts to permit this)
• When checking the inferred type
it :: forall t a t1.
(Num ([t] -> t1 -> [a] -> [a]), Num (t1 -> [a] -> [a]), Num t,
Num t1, Ord t1) =>
t1 -> [a] -> [a]