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)
HM2.
hm(syn);
29 Syntax syn =
new Apply(
new Ident(
"pair"),
new Con(
TypeInt.
con(3)));
30 HMType t =
HM2.
hm(syn);
31 assertEquals(
"{ v9 -> pair(v8:3,v9) }",t.str());
41 new Apply(
new Apply(
new Apply(
new Ident(
"if/else"),
42 new Apply(
new Ident(
"==0"),
new Ident(
"n"))),
44 new Apply(
new Apply(
new Ident(
"*"),
new Ident(
"n")),
45 new Apply(
new Ident(
"fact"),
46 new Apply(
new Ident(
"dec"),
new Ident(
"n")))))),
48 HMType t1 =
HM2.
hm(fact);
49 assertEquals(
"{ v25:int64 -> v25:int64 }",t1.str());
57 new Apply(
new Apply(
new Ident(
"pair"),
58 new Apply(
new Ident(
"x"),
new Con(
TypeInt.
con(3)))),
59 new Apply(
new Ident(
"x"),
new Con(
TypeStr.
ABC))));
60 HMType t1 =
HM2.
hm(x);
61 assertEquals(
"{ { v11:all -> v9 } -> pair(v9,v9) }",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 =
HM2.
hm(x);
75 assertEquals(
"pair(v9:all,v9:all)",t1.str());
79 @Test(expected = RuntimeException.class)
84 new Lambda(
"f",
new Apply(
new Ident(
"f"),
new Ident(
"f")));
94 new Apply(
new Ident(
"g"),
new Ident(
"g")));
95 HMType t1 =
HM2.
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))))));
113 HMType t1 =
HM2.
hm(syn);
114 assertEquals(
"{ v11 -> pair(v11,v11) }",t1.str());
122 new Lambda(
"f",
new Lambda(
"g",
new Lambda(
"arg",
new Apply(
new Ident(
"g"),
new Apply(
new Ident(
"f"),
new Ident(
"arg"))))));
124 HMType t1 =
HM2.
hm(syn);
125 assertEquals(
"{ { v10 -> v11 } -> { { v11 -> v12 } -> { v10 -> v12 } } }",t1.str());
139 new Apply(
new Ident(
"fun"),
new Ident(
"x")))),
140 new Apply(
new Apply(
new Ident(
"pair"),
141 new Apply(
new Apply(
new Ident(
"map"),
143 new Apply(
new Apply(
new Ident(
"map"),
145 new Ident(
"factor")),
new Con(
TypeFlt.
con(2.3)))));
146 HMType t1 =
HM2.
hm(syn);
147 assertEquals(
"pair(v12:*str,pair(v26:flt64,v26:flt64))",t1.str());
150 @Test(expected = RuntimeException.class)
164 new Apply(
new Apply(
new Apply(
new Ident(
"if/else"),
new Ident(
"p")),
166 new Apply(
new Apply(
new Ident(
"pair"),
new Ident(
"a")),
169 new Apply(
new Apply(
new Ident(
"pair"),
new Ident(
"b")),
170 new Apply(
new Apply(
new Ident(
"pair"),
new Con(
TypeInt.
con(3))),
175 new Apply(
new Ident(
"fun"),
new Ident(
"x")))),
177 new Apply(
new Apply(
new Ident(
"map"),
178 new Apply(
new Ident(
"fcn"),
new Ident(
"q"))),
181 HMType t1 =
HM2.
hm(syn);
182 assertEquals(
"TBD",t1.str());