1
A
回答
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'
相關問題
- 1. 哈斯克爾代數數據類型
- 2. 數據類型哈斯克爾錯誤
- 3. 哈斯克爾組數據類型
- 4. 打印數據類型 - 哈斯克爾
- 5. 哈斯克爾:數據類型
- 6. 哈斯克爾多態性與種類和類型變量
- 7. 哈斯克爾:「追加」類型的類
- 8. 哈斯克爾:剛性類型變量的錯誤
- 9. 哈斯克爾 - 模糊的類型變量
- 10. 哈斯克爾:類型類問題
- 11. 哈斯克爾繼承類型類
- 12. 哈斯克爾類型的表達式
- 13. 哈斯克爾GADT「Show'-實例類型變量扣除
- 14. 哈斯克爾類型誤區分配變量
- 15. 哈斯克爾類型類與代數數據類型
- 16. 操作變量(哈斯克爾)存儲
- 17. 哈斯克爾 - 存儲變量
- 18. 字符串變量名哈斯克爾
- 19. 哈斯克爾曖昧型
- 20. 哈斯克爾類型構造
- 21. 哈斯克爾/演算類型例如
- 22. 哈斯克爾 - 類型定義
- 23. 錯誤類型匹配哈斯克爾
- 24. 哈斯克爾返回類型混亂
- 25. 哈斯克爾類型錯誤
- 26. 哈斯克爾構造類型包含
- 27. 哈斯克爾 - 相關類型
- 28. 哈斯克爾:類型不匹配
- 29. 哈斯克爾monad返回類型
- 30. 哈斯克爾:確定功能類型
是的。 –
Alec