2016-08-06 15 views
0

対変数とGHCiの中の関数を呼び出すときに、私は数の絶対値を見つけるために、簡単な関数を定義した:異なる振る舞いリテラル数

変数

Prelude> let x = -10 
Prelude| 
Prelude> abs x 
10 

通話で関数を呼び出す

let abs n | n >= 0 = n | otherwise = -n 

値を持つ関数

Prelude> abs -10 
<interactive>:65:1: 
    Non type-variable argument in the constraint: Num (a -> a) 
    (Use FlexibleContexts to permit this) 
    When checking that ‘it’ has the inferred type 
    it :: forall a. (Num a, Num (a -> a), Ord a) => a -> a 

私は2番目の呼び出しの失敗を理解していませんation。私はGHCiバージョン7.10.2を使用しています。

+0

より正確でより正確なタイトルを書いてください。 –

答えて

4

abs -10実際には、を意味し、abs10の差を意味します。

あなたはabs (-10)が必要です。

+0

ありがとう、それはそれに答える。 – randominstanceOfLivingThing