0
錯誤消息:如何使用實例?
ho8.hs:17:19:
Ambiguous type variable `a0' in the constraints:
(PPLetter a0) arising from a use of `ppLetter' at ho8.hs:17:19-26
(Num a0) arising from the literal `3' at ho8.hs:17:28
Probable fix: add a type signature that fixes these type variable(s)
In the first argument of `print', namely `(ppLetter 3)'
In the expression: print (ppLetter 3)
In the expression: do { print (ppLetter 3) }
Failed, modules loaded: none.
源代碼:
module Main where
import Data.List(nub)
import qualified Text.PrettyPrint.HughesPJ as PP
import Text.PrettyPrint.HughesPJ(Doc,text,int,(<>),(<+>),($+$),render)
class PPLetter a where
ppLetter :: a -> Doc
instance PPLetter Int where
ppLetter a = text ("p"++show a)
instance PPLetter Char where
ppLetter = PP.char
main = do {print (ppLetter 3);}
我更新的問題,並得到另一個錯誤 – Jo0o0 2011-04-16 11:19:52