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)
HM3.
hm(syn);
29 Syntax syn =
new Apply(
new Ident(
"pair"),
new Con(
TypeInt.
con(3)));
30 HMType t =
HM3.
hm(syn);
31 assertEquals(
"{ v25 -> pair(v21:3,v25$) }",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 =
HM3.
hm(fact);
49 assertEquals(
"{ v31:int64 -> v31$ }",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 =
HM3.
hm(x);
61 assertEquals(
"{ { v22:all -> v23 } -> pair(v23$,v23$) }",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 =
HM3.
hm(x);
75 assertEquals(
"pair(v22:all,v22$)",t1.str());
84 new Lambda(
"y",
new Ident(
"y")),
85 new Apply(
new Apply(
new Ident(
"pair"),
86 new Apply(
new Ident(
"x"),
new Con(
TypeInt.
con(3)))),
87 new Apply(
new Ident(
"x"),
new Con(
TypeStr.
ABC))));
89 HMType t1 =
HM3.
hm(x);
90 assertEquals(
"pair(v27:3,v23:\"abc\")",t1.str());
98 new Lambda(
"f",
new Apply(
new Ident(
"f"),
new Ident(
"f")));
99 HMType t1 =
HM3.
hm(x);
101 assertEquals(
"{ { v23$ -> v22 } -> v22$ }",t1.str());
110 new Apply(
new Ident(
"g"),
new Ident(
"g")));
111 HMType t1 =
HM3.
hm(x);
112 assertEquals(
"v25:5",t1.str());
122 new Lambda(
"x",
new Ident(
"g")),
124 new Apply(
new Ident(
"pair"),
125 new Apply(
new Ident(
"f"),
new Con(
TypeInt.
con(3)))
127 new Apply(
new Ident(
"f"),
new Con(
TypeInt.
con(1))))));
129 HMType t1 =
HM3.
hm(syn);
130 assertEquals(
"{ v21 -> pair(v21$,v21$) }",t1.str());
138 new Lambda(
"f",
new Lambda(
"g",
new Lambda(
"arg",
new Apply(
new Ident(
"g"),
new Apply(
new Ident(
"f"),
new Ident(
"arg"))))));
140 HMType t1 =
HM3.
hm(syn);
141 assertEquals(
"{ { v23 -> v24 } -> { { v24$ -> v27 } -> { v23$ -> v27$ } } }",t1.str());
154 new Apply(
new Ident(
"fun"),
new Ident(
"x")))),
155 new Apply(
new Apply(
new Ident(
"pair"),
156 new Apply(
new Apply(
new Ident(
"map"),
158 new Apply(
new Apply(
new Ident(
"map"),
160 new Ident(
"factor")),
new Con(
TypeFlt.
con(2.3)))));
161 HMType t1 =
HM3.
hm(syn);
162 assertEquals(
"pair(v36:*str,pair(v24:flt64,v24$))",t1.str());
165 @Test(expected = RuntimeException.class)
180 new Apply(
new Apply(
new Apply(
new Ident(
"if/else"),
new Ident(
"p")),
182 new Apply(
new Apply(
new Ident(
"pair"),
new Ident(
"a")),
185 new Apply(
new Apply(
new Ident(
"pair"),
new Ident(
"b")),
186 new Apply(
new Apply(
new Ident(
"pair"),
new Con(
TypeInt.
con(3))),
191 new Apply(
new Ident(
"fun"),
new Ident(
"x")))),
193 new Apply(
new Apply(
new Ident(
"map"),
194 new Apply(
new Ident(
"fcn"),
new Ident(
"q"))),
196 HMType t1 =
HM3.
hm(syn);
199 assertEquals(
"TBD",t1.str());
202 @Test(expected = RuntimeException.class)
212 new Apply(
new Apply(
new Apply(
new Ident(
"if/else"),
new Ident(
"p")),
214 new Ident(
"factor")));
215 HMType t1 =
HM3.
hm(syn);
216 assertEquals(
"Cannot unify v27:int1 and pair24(v23:Real,v23$)",t1.str());