
Hello, I would like to ask something that results in when I have the following commands data Color = Red | Green | Blue | Indigo | Violet deriving (Enum,Show,Read) (read.show) x <interactive>:1:1: Ambiguous type variable `a' in the constraint: `Read a' arising from a use of `read' at <interactive>:1:1-4 Probable fix: add a type signature that fixes these type variable(s) I also receive the same message with the following: *Test > let x = Branch (Branch (Branch (Leaf 'a') (Leaf 'b')) (Leaf 'c') ) (Leaf 'd') *Test > x <<<'a'|'b'>|'c'>|'d'> *Test > (read.show) x <interactive>:1:1: Ambiguous type variable `a' in the constraint: `Read a' arising from a use of `read' at <interactive>:1:1-4 Probable fix: add a type signature that fixes these type variable(s) data Tree a = Leaf a | Branch (Tree a) (Tree a) --type ShowS = String -> String showsTree :: (Show a) => Tree a -> ShowS showsTree (Leaf x) = shows x showsTree (Branch l r) = ('<':).showsTree l . ('|':) . showsTree r . ('>':) --type ReadS a = String -> [(a,String)] readsTree :: (Read a) => ReadS (Tree a) readsTree s = [(Branch l r, x) | ("<",t) <- lex s, (l,u) <- readsTree t, ("|",v) <- lex u, (r,w) <- readsTree v, (">",x) <-lex w] ++ [(Leaf x, t) | (x,t) <- read s] instance Show a => Show (Tree a) where showsPrec _ x = showsTree x instance Read a => Read (Tree a) where readsPrec _ s = readsTree s Why is this happen? Maybe an example with a simple application of the Class Read would be helpful. Thanks -- View this message in context: http://www.nabble.com/Usage-of-Read-Class-tp16381441p16381441.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.