\r
show_{|Int|} i c = [toString i:c]\r
show_{|Bool|} b c = [toString b:c]\r
+show_{|UNIT|} _ c = c\r
\r
show a = show_{|*|} a []\r
\r
Just (y,[]) = x === y\r
_ = False\r
\r
-/**************** End Prelude, add all new code below this line *************************/\r
-\r
-//------------------ tests --------------\r
-\r
-Start = and [test b \\ b <- [False, True]]\r
+/***** End Prelude, add all new code below this line *************************/\r
+//Show stuff\r
+show_{|OBJECT|} f (OBJECT x) c = f x c\r
+show_{|CONS of {gcd_name, gcd_arity}|} f (CONS x) c\r
+| gcd_arity == 0 = [gcd_name:f x c]\r
+| otherwise = ["(":gcd_name:f x [")":c]]\r
+show_{|PAIR|} f1 f2 (PAIR x1 x2) c = f1 x1 (f2 x2 c)\r
+show_{|EITHER|} f _ (LEFT x) c = f x c\r
+show_{|EITHER|} _ f (RIGHT x) c = f x c\r
+show_{|(,)|} f1 f2 (x1, x2) c = ["("] ++ f1 x1 [",":f2 x2 c]++[")"]\r
+\r
+derive show_ T, [], Color, Tree\r
+\r
+//Parse stuff (monads would make this more neat)\r
+parse{|Int|} [i:r] = Just (toInt i, r)\r
+parse{|Int|} _ = Nothing\r
+parse{|UNIT|} r = Just (UNIT, r)\r
+parse{|OBJECT|} f r = case f r of\r
+ Just (x, r) = Just (OBJECT x, r)\r
+ _ = Nothing\r
+parse{|CONS of {gcd_name, gcd_arity}|} f r\r
+| gcd_arity == 0 = case r of\r
+ [gcd_name:r] = case f r of\r
+ Just (x, r) = Just (CONS x, r)\r
+ _ = Nothing\r
+ _ = Nothing\r
+| otherwise = case r of\r
+ ["(",gcd_name:r] = case f r of\r
+ Just (x, r) = Just (CONS x, r % (0, (length r) - 2))\r
+ _ = Nothing\r
+ _ = Nothing\r
+parse{|PAIR|} f1 f2 r = case f1 r of\r
+ Just (x1, r) = case f2 r of\r
+ Just (x2, r) = Just (PAIR x1 x2, r)\r
+ _ = Nothing\r
+ _ = Nothing\r
+parse{|EITHER|} f1 f2 r = case f2 r of\r
+ Just (x, r) = Just (RIGHT x, r)\r
+ _ = case f1 r of\r
+ Just (x, r) = Just (LEFT x, r)\r
+ _ = Nothing\r
+parse{|(,)|} f1 f2 ["(":r] = case f1 r of\r
+ Just (x1, r) = case r of\r
+ [",":r] = case f2 r of\r
+ Just (x2, r) = Just ((x1, x2), r % (0, (length r) - 2))\r
+ _ = Nothing\r
+ _ = Nothing\r
+ _ = Nothing\r
+\r
+derive parse T, [], Color, Tree\r
+Start = show 42\r