2016-12-01 30 views

回答

5

是的。你可以用一個忽略它的參數的函數來觀察它。

foo :: a -> a -> Bool 
foo _ _ = True 

使用相同類型的兩個參數調用它。

Prelude> foo 1 1 
True 
Prelude> foo 'x' 'x' 
True 

與不同類型的兩個參數調用它會產生一個錯誤類型,取決於您選擇哪種類型的具體錯誤。

Prelude> foo 1 'x' 

<interactive>:5:5: 
    No instance for (Num Char) arising from the literal ‘1’ 
    In the first argument of ‘foo’, namely ‘1’ 
    In the expression: foo 1 'x' 
    In an equation for ‘it’: it = foo 1 'x' 
Prelude> foo 'x' (1::Int) 

<interactive>:8:10: 
    Couldn't match expected type ‘Char’ with actual type ‘Int’ 
    In the second argument of ‘foo’, namely ‘(1 :: Int)’ 
    In the expression: foo 'x' (1 :: Int) 
    In an equation for ‘it’: it = foo 'x' (1 :: Int) 
Prelude> foo (1::Int) 'x' 

<interactive>:9:14: 
    Couldn't match expected type ‘Int’ with actual type ‘Char’ 
    In the second argument of ‘foo’, namely ‘'x'’ 
    In the expression: foo (1 :: Int) 'x' 
    In an equation for ‘it’: it = foo (1 :: Int) 'x'