implementation module ast import StdList import StdOverloaded import Data.Func import Text.PPrint instance toString AST where toString a = display $ renderCompact $ pretty a instance toString Function where toString a = display $ renderCompact $ pretty a instance toString Expression where toString a = display $ renderCompact $ pretty a instance toString Value where toString a = display $ renderCompact $ pretty a instance Pretty Expression where pretty (Literal v) = pretty v pretty (Variable v) = string v pretty (Apply a b) = parens (pretty a <+> pretty b) pretty (Lambda a b) = string "\\" <-> string a <+> string "->" <+> pretty b pretty (Let v a b) = string "let" <+> string v <+> string "=" <+> pretty a <+> string "in" <+> pretty b pretty (Code b) = string "code" <+> string b instance Pretty Function where pretty (Function n args a) = string n <+> fold (<+>) (map string args) <+> string "=" <+> pretty a instance Pretty AST where pretty (AST a) = pretty a instance Pretty Value where pretty (Int i) = int i pretty (Bool b) = bool b pretty (Char c) = char c