inference from haskell writing
[fp.git] / ast.icl
1 implementation module ast
2
3 import StdList
4 import StdOverloaded
5 import Data.Func
6 import Text.PPrint
7
8 instance toString AST where toString a = display $ renderCompact $ pretty a
9 instance toString Function where toString a = display $ renderCompact $ pretty a
10 instance toString Expression where toString a = display $ renderCompact $ pretty a
11 instance toString Value where toString a = display $ renderCompact $ pretty a
12
13 instance Pretty Expression
14 where
15 pretty (Literal v) = pretty v
16 pretty (Variable v) = string v
17 pretty (Apply a b) = parens (pretty a <+> pretty b)
18 pretty (Lambda a b) = string "\\" <-> string a <+> string "->" <+> pretty b
19 pretty (Let v a b) = string "let" <+> string v <+> string "=" <+> pretty a <+> string "in" <+> pretty b
20 pretty (Code b) = string "code" <+> string b
21
22 instance Pretty Function
23 where
24 pretty (Function n args a) = string n <+> fold (<+>) (map string args) <+> string "=" <+> pretty a
25
26 instance Pretty AST
27 where
28 pretty (AST a) = pretty a
29
30 instance Pretty Value
31 where
32 pretty (Int i) = int i
33 pretty (Bool b) = bool b
34 pretty (Char c) = char c