+
+instance toString AST where
+ toString (AST v f) = concat (print v ++ ["\n":print f])
+
+class print a :: a -> [String]
+
+instance print [a] | print a where
+ print [] = ["\n"]
+ print [v:vs] = print v ++ ["\n":print vs]
+
+instance print VarDecl where
+ print (VarDecl i t e) = print t ++ [" ":i:"=":print e] ++ [";"]
+instance print FunDecl where
+ print _ = ["Function printing not yet implemented"]
+
+instance print Type where
+ print (TupleType t1 t2) = ["(":print t1] ++ [", ":print t2] ++ [")"]
+ print (ListType t) = ["[":print t] ++ ["]"]
+ print (IdType s) = [s]
+ print IntType = ["Int"]
+ print BoolType = ["Bool"]
+ print CharType = ["Char"]
+ print VarType = ["var"]
+
+instance print Expr where
+ print (VarExpr i Nothing) = [i]
+ print (VarExpr i (Just mf)) = [i, case mf of
+ FieldHd = ".hd"; FieldTl = ".tl"
+ FieldSnd = ".snd"; FieldFst = ".fst"]
+ print (Op2Expr e1 o e2) = print e1 ++ [case o of
+ BiPlus = "+"; BiMinus = "-"; BiTimes = "*"; BiDivide = "/"
+ BiMod = "%"; BiEquals = "="; BiLesser = "<"; BiGreater = ">"
+ BiLesserEq = "<="; BiGreaterEq = ">="; BiUnEqual = "!=";
+ BiAnd = "&&"; BiOr = "||"; BiCons = ":"
+ :print e2]
+ print (Op1Expr o e) = [case o of
+ UnNegation = "!"; UnMinus = "-"
+ :print e]
+ print (IntExpr i) = [toString i]
+ print (CharExpr c) = ["\'", case c of
+ '\b' = "\\b"; '\f' = "\\f"; '\n' = "\\n"
+ '\r' = "\\r"; '\t' = "\\t"; '\v' = "\\v"
+ c = if (c == toChar 7) "\\a" (toString c)
+ ,"\'"]
+ print (BoolExpr b) = [toString b]
+ print (FunExpr i es) = pe ++ flatten [[",":x]\\x<-tl pes]
+ where [pe:pes] = map print es
+ print EmptyListExpr = ["[]"]
+ print (TupleExpr e1 e2) = ["(":print e1] ++ [",":print e2] ++ [")"]