我在哪裏編寫了下面的代碼,Haskell不會編譯。爲什麼「實例Monad(Gang String)」編譯錯誤
data Gang b a=Gang{getGang::(a,b)}
instance Monad (Gang String) where
return x = Gang (x,"")
(Gang(x,log)) >>=f = let Gang(x1,log1)= f x in Gang(x1,log++log1)
編譯器輸出:
Illegal instance declaration for `Monad (Gang String)'
(All instance types must be of the form (T a1 ... an)
where a1 ... an are *distinct type variables*,
and each type variable appears at most once in the instance head.
Use -XFlexibleInstances if you want to disable this.)
In the instance declaration for `Monad (Gang String)'
後,我用 「ghci中-XFlexibleInstances」 推出ghci中並加載文件時,它編譯成功。爲什麼?
嗯...因爲它不是Haskell 98,沒有-X標誌的GHC實現了Haskell 98? –
@ n.m。現在,Haskell 2010實際上就是這樣。這並不是說所有的差別都很大。 –