Add if..then..else
[hcoop/domtool2.git] / src / tycheck.sml
index def1463..f68100f 100644 (file)
@@ -571,6 +571,33 @@ fun checkExp G (eAll as (e, loc)) =
 
          | ESkip => (TAction ((CPrefix (CRoot, loc), loc),
                               SM.empty, SM.empty), loc)
+
+         | EIf (e1, e2, e3) =>
+           let
+               val t = (newUnif (), loc)
+
+               val t1 = checkExp G e1
+               val t2 = checkExp G e2
+               val t3 = checkExp G e3
+               val bool = (TBase "bool", loc)
+           in
+               (subTyp (t1, bool))
+               handle Unify ue =>
+                      dte (WrongType ("\"If\" test",
+                                      e1,
+                                      t1,
+                                      bool,
+                                      SOME ue));
+               subTyp (t2, t);
+               (subTyp (t3, t))
+               handle Unify ue =>
+                      dte (WrongType ("\"Else\" case",
+                                      eAll,
+                                      t3,
+                                      t2,
+                                      SOME ue));
+               t
+           end
     end
 
 exception Ununif