1 package com.cliffc.aa.HM;
4 import org.junit.Before;
8 import static org.junit.Assert.assertEquals;
14 @Test(expected = RuntimeException.class)
16 Syntax syn =
new Ident(
"fred");
23 HMVar t = (HMVar)
HM1.
HM(syn);
29 Syntax syn =
new Apply(
new Ident(
"pair"),
new Con(
TypeInt.
con(3)));
30 HMType t =
HM1.
HM(syn);
31 assertEquals(
"{ v9 -> pair(v8:3,v9$) }",t.str());
39 new Apply(
new Apply(
new Ident(
"pair"),
40 new Apply(
new Ident(
"x"),
new Con(
TypeInt.
con(3)))),
41 new Apply(
new Ident(
"x"),
new Con(
TypeStr.
ABC))));
42 HMType t1 =
HM1.
HM(x);
43 assertEquals(
"{ { v11:all -> v9 } -> pair(v9$,v9$) }",t1.str());
53 new Apply(
new Apply(
new Apply(
new Ident(
"if/else"),
54 new Apply(
new Ident(
"==0"),
new Ident(
"n"))),
56 new Apply(
new Apply(
new Ident(
"*"),
new Ident(
"n")),
57 new Apply(
new Ident(
"fact"),
58 new Apply(
new Ident(
"dec"),
new Ident(
"n")))))),
60 HMType t1 =
HM1.
HM(fact);
61 assertEquals(
"{ v25:int64 -> v25$ }",t1.str());
68 new Apply(
new Lambda(
"x",
69 new Apply(
new Apply(
new Ident(
"pair"),
70 new Apply(
new Ident(
"x"),
new Con(
TypeInt.
con(3)))),
71 new Apply(
new Ident(
"x"),
new Con(
TypeStr.
ABC)))),
72 new Lambda(
"y",
new Ident(
"y")));
74 HMType t1 =
HM1.
HM(x);
75 assertEquals(
"pair(v17:all,v17$)",t1.str());
78 @Test(expected = RuntimeException.class)
83 new Lambda(
"f",
new Apply(
new Ident(
"f"),
new Ident(
"f")));
84 HMType t1 =
HM1.
HM(x);
85 assertEquals(
"TBD",t1.str());
94 new Apply(
new Ident(
"g"),
new Ident(
"g")));
95 HMType t1 =
HM1.
HM(x);
96 assertEquals(
"v12:5",t1.str());
106 new Lambda(
"x",
new Ident(
"g")),
108 new Apply(
new Ident(
"pair"),
109 new Apply(
new Ident(
"f"),
new Con(
TypeInt.
con(3)))
111 new Apply(
new Ident(
"f"),
new Con(
TypeInt.
con(1))))));
112 HMType t1 =
HM1.
HM(syn);
113 assertEquals(
"{ v11 -> pair(v11$,v11$) }",t1.str());
121 new Lambda(
"f",
new Lambda(
"g",
new Lambda(
"arg",
new Apply(
new Ident(
"g"),
new Apply(
new Ident(
"f"),
new Ident(
"arg"))))));
123 HMType t1 =
HM1.
HM(syn);
124 assertEquals(
"{ { v10 -> v11 } -> { { v11$ -> v12 } -> { v10$ -> v12$ } } }",t1.str());
137 new Apply(
new Ident(
"fun"),
new Ident(
"x")))),
138 new Apply(
new Apply(
new Ident(
"pair"),
139 new Apply(
new Apply(
new Ident(
"map"),
141 new Apply(
new Apply(
new Ident(
"map"),
143 new Ident(
"factor")),
new Con(
TypeFlt.
con(2.3)))));
144 HMType t1 =
HM1.
HM(syn);
145 assertEquals(
"pair(v12:*str,pair(v26:flt64,v26$))",t1.str());
148 @Test(expected = RuntimeException.class)
162 new Apply(
new Apply(
new Apply(
new Ident(
"if/else"),
new Ident(
"p")),
164 new Apply(
new Apply(
new Ident(
"pair"),
new Ident(
"a")),
167 new Apply(
new Apply(
new Ident(
"pair"),
new Ident(
"b")),
168 new Apply(
new Apply(
new Ident(
"pair"),
new Con(
TypeInt.
con(3))),
173 new Apply(
new Ident(
"fun"),
new Ident(
"x")))),
175 new Apply(
new Apply(
new Ident(
"map"),
176 new Apply(
new Ident(
"fcn"),
new Ident(
"q"))),
179 HMType t1 =
HM1.
HM(syn);
180 assertEquals(
"TBD",t1.str());
190 new Let(
"cons",
new Lambda2(
"x",
"y",
191 new Lambda(
"cadr",
new Apply(
new Ident(
"cadr"),
new Ident(
"x"),
new Ident(
"y")))),
192 new Let(
"cdr",
new Lambda(
"mycons",
new Apply(
new Ident(
"mycons"),
new Lambda2(
"p",
"q",
new Ident(
"q")))),
193 new Apply(
new Ident(
"cdr"),
195 HMType t1 =
HM1.
HM(syn);
196 assertEquals(
"v20:3",t1.str());
203 new Let(
"f0",
new Lambda2(
"f",
"x",
204 new Apply(
new Ident(
"if/else3"),
205 new Apply(
new Ident(
"==0"),
new Ident(
"x")),
207 new Apply(
new Ident(
"f"),
208 new Apply(
new Ident(
"f0"),
210 new Apply(
new Ident(
"dec"),
new Ident(
"x"))),
214 new Apply(
new Ident(
"f0"),
new Ident(
"*2"),
new Con(
TypeInt.
con(99))));
215 HMType t1 =
HM1.
HM(syn);
216 assertEquals(
"v24:int64",t1.str());
234 new Lambda2(
"x",
"y",
new Lambda(
"cadr",
new Apply(
new Ident(
"cadr"),
new Ident(
"x"),
new Ident(
"y")))),
236 new Lambda(
"mycons",
new Apply(
new Ident(
"mycons"),
new Lambda2(
"p",
"q",
new Ident(
"q")))),
237 new Apply(
new Ident(
"cdr"),
238 new Apply(
new Ident(
"cons"),
240 new Lambda(
"z",
new Apply(
new Ident(
"g"),
new Ident(
"z"))))))),
241 new Apply(
new Apply(
new Ident(
"pair"),
242 new Apply(
new Ident(
"fgz"),
new Con(
TypeInt.
con(3)))),
243 new Apply(
new Ident(
"fgz"),
new Con(
TypeInt.
con(5))))));
244 HMType t1 =
HM1.
HM(syn);
245 assertEquals(
"{ { v27:nint8 -> v31 } -> pair(v31$,v31$) }",t1.str());