我有一個HS文件,試圖超載& &操作超載全球&&運營商在Haskell編譯失敗
(&&)::Bool->Bool->Bool
True && x = x
False && _ = False
and' :: (Bool)->Bool
and' xs=foldr (&&) True xs
當前奏進口的,有錯誤:
Ambiguous occurrence ‘&&’
It could refer to either ‘Main.&&’, defined at D:\baby.hs:2:6
or ‘Prelude.&&’,
imported from ‘Prelude’ at D:\baby.hs:1:1
(and originally defined in ‘GHC.Classes’)
所以我將最後一行改爲
and' xs=foldr (Main.&&) True xs
現在它打印新的er ror留言:
Couldn't match expected type ‘t0 Bool’ with actual type ‘Bool’
In the third argument of ‘foldr’, namely ‘xs’
In the expression: foldr (Main.&&) True xs
如何解決此問題?謝謝。
'xs'的類型應該是'[Bool]'而不是'(Bool)'。 – zakyggaps