1 -- !!! Show/Read deriving example given in the Haskell Report.
2 module Main(main) where
6 = Leaf a | (Tree a) :^: (Tree a)
13 val2 = Leaf 2 :^: Leaf (-1)
19 print ((read (show val1))::Tree Int)
20 print ((read (show val2))::Tree Int)
21 print ((read (show val1))::Tree Integer)
22 print ((read (show val2))::Tree Integer)
25 instance (Show a) => Show (Tree a) where
27 showsPrec d (Leaf m) = showParen (d >= 10) showStr
29 showStr = showString "Leaf " . showsPrec 10 m
31 showsPrec d (u :^: v) = showParen (d > 4) showStr
33 showStr = showsPrec 5 u .
37 instance (Read a) => Read (Tree a) where
39 readsPrec d r = readParen (d > 4)
41 (u,s) <- readsPrec 5 r,
43 (v,w) <- readsPrec 5 t]) r
48 (m,t) <- readsPrec 10 s]) r