5 Skeleton for exercise 3.3 and 3.4.
6 To be used in a project with the environment Everything,
7 or StdEnv with an import of StdMaybe from StdLib
9 Pieter Koopman, pieter@cs.ru.nl
12 import StdEnv, StdGeneric, StdMaybe, GenEq
14 //------------------ show --------------
15 generic show_ a :: a [String] -> [String]
17 show_{|Int|} i c = [toString i:c]
18 show_{|Bool|} b c = [toString b:c]
20 show a = show_{|*|} a []
22 //------------------ parse --------------
24 :: Result a :== Maybe (a, [String])
26 generic parse a :: [String] -> Result a
28 parse{|Bool|} ["True" :r] = Just (True ,r)
29 parse{|Bool|} ["False":r] = Just (False,r)
30 parse{|Bool|} _ = Nothing
32 //------------------ some data types --------------
35 :: Color = Red | Yellow | Blue
36 :: Tree a = Tip | Bin a (Tree a) (Tree a)
38 //------------------ general useful --------------
40 instance + String where (+) s t = s+++t
41 derive bimap Maybe, []
43 //------------------ to test if parse and show work properly --------------
45 test :: t -> Bool | gEq{|*|}, show_{|*|}, parse{|*|} t
47 = case parse{|*|} (show x) of
51 /**************** End Prelude, add all new code below this line *************************/
53 //------------------ tests --------------
55 Start = and [test b \\ b <- [False, True]]