hi_copy.hs
waxOn = x
where
z = 7
y = z 18
k = y ^ 2
x = k * 5
triple = a
where
a = a * 3
然后加載。
ghci> :load hi_copy.hs
[1 of 1] Compiling Main ( hi_copy.hs, interpreted )
Ok, one module loaded.
然后運行
triple waxOn
<interactive>:122:1: error:
? Couldn't match expected type ‘Integer -> t’
with actual type ‘Integer’
? The function ‘triple’ is applied to one value argument,
but its type ‘Integer’ has none
In the expression: triple waxOn
In an equation for ‘it’: it = triple waxOn
? Relevant bindings include it :: t (bound at <interactive>:122:1)
運行3 * waxOn將起作用。但現在我不知道如何triple waxOn作業。meta:到目前為止還沒有在haskell中學習型別。可能已經存在其他好的答案。但我不明白其他人的好答案。
uj5u.com熱心網友回復:
你triple不帶任何引數。它只回傳一個值,該值將是無限遞回的結果 where ais ((((…) * 3) * 3) * 3)。
您應該將引數作為輸入,因此:
triple :: Num a => a -> a
triple a = a * 3
或更短:
triple :: Num a => a -> a
triple = (3 *)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/448834.html
標籤:哈斯克尔
上一篇:兩個字串之間的正則運算式子字串
