-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExamples.hs
94 lines (84 loc) · 1.83 KB
/
Examples.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
{-# LANGUAGE OverloadedStrings #-}
module Examples where
import qualified Data.Map as M
import Wave.Ast
import Wave.Common
lit :: File ()
lit =
exprToFile $
ELit $ LInt 7
variant :: File ()
variant =
exprToFile $
EVariant $ Variant "Foo" (ERecord $ M.fromList [("x", ELit $ LString "wave")])
patmatch1 :: File ()
patmatch1 =
exprToFile $
ECase
(ELit $ LInt 0)
[ (PWildcard, ELit $ LInt 1)
]
patmatch2 :: File ()
patmatch2 =
exprToFile $
ECase
(ELit $ LInt 0)
[ (PLit (LInt 1), ELit $ LInt 1),
(PLit (LInt 0), ELit $ LInt 0)
]
patmatch3 :: File ()
patmatch3 =
exprToFile $
ECase
(ELit $ LInt 17)
[ (PLit (LInt 1), ELit $ LInt 1),
(PLit (LInt 0), ELit $ LInt 0),
(PVar "v", EVar "v")
]
patmatch4 :: File ()
patmatch4 =
exprToFile $
ECase
( EVariant $
Variant "Nil" $
ERecord $
M.fromList
[ ("head", ELit $ LInt 0),
("tail", ERecord mempty)
]
)
[ (PVariant $ Variant "Nil" (PVar "obj"), ERecordAccess (EVar "obj") "head")
]
patmatch5 :: File ()
patmatch5 =
exprToFile $
ECase
( EVariant $
Variant "Nil" $
ERecord $
M.fromList
[ ("head", ELit $ LInt 0),
("tail", ERecord mempty)
]
)
[ ( PVariant $
Variant
"Nil"
( PRecord $
M.fromList
[ ("head", PVar "head"),
("tail", PRecord mempty)
]
),
EVar "head"
)
]
exprToFile :: Expr () -> File ()
exprToFile e =
File
[ TermDef $
Function
"main"
[]
[SExpr $ EFfi "console.log" [e]]
]