Mercurial > urweb
comparison src/elaborate.sml @ 228:19e5791923d0
Resolving lingering type class constraints
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 21 Aug 2008 14:45:31 -0400 |
parents | bbe5899a9585 |
children | c466678af854 |
comparison
equal
deleted
inserted
replaced
227:524e10c91478 | 228:19e5791923d0 |
---|---|
1121 (L'.TFun ((L'.CApp ((L'.CRel 0, loc), (L'.CRecord (dom, []), loc)), loc), | 1121 (L'.TFun ((L'.CApp ((L'.CRel 0, loc), (L'.CRecord (dom, []), loc)), loc), |
1122 (L'.TCFun (L'.Explicit, "r", (L'.KRecord dom, loc), | 1122 (L'.TCFun (L'.Explicit, "r", (L'.KRecord dom, loc), |
1123 (L'.CApp ((L'.CRel 1, loc), (L'.CRel 0, loc)), loc)), loc)), | 1123 (L'.CApp ((L'.CRel 1, loc), (L'.CRel 0, loc)), loc)), loc)), |
1124 loc)), loc)), loc) | 1124 loc)), loc)), loc) |
1125 | 1125 |
1126 datatype constraint = | |
1127 Disjoint of D.goal | |
1128 | TypeClass of E.env * L'.con * L'.exp option ref * ErrorMsg.span | |
1129 | |
1130 val enD = map Disjoint | |
1131 | |
1126 fun elabHead (env, denv) (e as (_, loc)) t = | 1132 fun elabHead (env, denv) (e as (_, loc)) t = |
1127 let | 1133 let |
1128 fun unravel (t, e) = | 1134 fun unravel (t, e) = |
1129 let | 1135 let |
1130 val (t, gs) = hnormCon (env, denv) t | 1136 val (t, gs) = hnormCon (env, denv) t |
1135 val u = cunif (loc, k) | 1141 val u = cunif (loc, k) |
1136 | 1142 |
1137 val (e, t, gs') = unravel (subConInCon (0, u) t', | 1143 val (e, t, gs') = unravel (subConInCon (0, u) t', |
1138 (L'.ECApp (e, u), loc)) | 1144 (L'.ECApp (e, u), loc)) |
1139 in | 1145 in |
1140 (e, t, gs @ gs') | 1146 (e, t, enD gs @ gs') |
1141 end | 1147 end |
1142 | _ => (e, t, gs) | 1148 | _ => (e, t, enD gs) |
1143 end | 1149 end |
1144 in | 1150 in |
1145 unravel (t, e) | 1151 unravel (t, e) |
1146 end | 1152 end |
1147 | 1153 |
1460 let | 1466 let |
1461 val (e', et, gs1) = elabExp (env, denv) e | 1467 val (e', et, gs1) = elabExp (env, denv) e |
1462 val (t', _, gs2) = elabCon (env, denv) t | 1468 val (t', _, gs2) = elabCon (env, denv) t |
1463 val gs3 = checkCon (env, denv) e' et t' | 1469 val gs3 = checkCon (env, denv) e' et t' |
1464 in | 1470 in |
1465 (e', t', gs1 @ gs2 @ gs3) | 1471 (e', t', gs1 @ enD gs2 @ enD gs3) |
1466 end | 1472 end |
1467 | 1473 |
1468 | L.EPrim p => ((L'.EPrim p, loc), primType env p, []) | 1474 | L.EPrim p => ((L'.EPrim p, loc), primType env p, []) |
1469 | L.EVar ([], s) => | 1475 | L.EVar ([], s) => |
1470 (case E.lookupE env s of | 1476 (case E.lookupE env s of |
1508 (L'.TFun (dom, ran), _) => | 1514 (L'.TFun (dom, ran), _) => |
1509 let | 1515 let |
1510 val (dom, gs4) = normClassConstraint (env, denv) dom | 1516 val (dom, gs4) = normClassConstraint (env, denv) dom |
1511 in | 1517 in |
1512 case E.resolveClass env dom of | 1518 case E.resolveClass env dom of |
1513 NONE => (expError env (Unresolvable (loc, dom)); | 1519 NONE => |
1514 (eerror, cerror, [])) | 1520 let |
1515 | SOME pf => ((L'.EApp (e1', pf), loc), ran, gs1 @ gs2 @ gs3 @ gs4) | 1521 val r = ref NONE |
1522 in | |
1523 ((L'.EUnif r, loc), ran, [TypeClass (env, dom, r, loc)]) | |
1524 end | |
1525 | SOME pf => ((L'.EApp (e1', pf), loc), ran, gs1 @ gs2 @ enD gs3 @ enD gs4) | |
1516 end | 1526 end |
1517 | _ => (expError env (OutOfContext (loc, SOME (e1', t1))); | 1527 | _ => (expError env (OutOfContext (loc, SOME (e1', t1))); |
1518 (eerror, cerror, [])) | 1528 (eerror, cerror, [])) |
1519 end | 1529 end |
1520 | L.EWild => (expError env (OutOfContext (loc, NONE)); | 1530 | L.EWild => (expError env (OutOfContext (loc, NONE)); |
1531 val t = (L'.TFun (dom, ran), dummy) | 1541 val t = (L'.TFun (dom, ran), dummy) |
1532 | 1542 |
1533 val gs4 = checkCon (env, denv) e1' t1 t | 1543 val gs4 = checkCon (env, denv) e1' t1 t |
1534 val gs5 = checkCon (env, denv) e2' t2 dom | 1544 val gs5 = checkCon (env, denv) e2' t2 dom |
1535 | 1545 |
1536 val gs = gs1 @ gs2 @ gs3 @ gs4 @ gs5 | 1546 val gs = gs1 @ gs2 @ gs3 @ enD gs4 @ enD gs5 |
1537 in | 1547 in |
1538 ((L'.EApp (e1', e2'), loc), ran, gs) | 1548 ((L'.EApp (e1', e2'), loc), ran, gs) |
1539 end | 1549 end |
1540 | L.EAbs (x, to, e) => | 1550 | L.EAbs (x, to, e) => |
1541 let | 1551 let |
1550 end | 1560 end |
1551 val (e', et, gs2) = elabExp (E.pushERel env x t', denv) e | 1561 val (e', et, gs2) = elabExp (E.pushERel env x t', denv) e |
1552 in | 1562 in |
1553 ((L'.EAbs (x, t', et, e'), loc), | 1563 ((L'.EAbs (x, t', et, e'), loc), |
1554 (L'.TFun (t', et), loc), | 1564 (L'.TFun (t', et), loc), |
1555 gs1 @ gs2) | 1565 enD gs1 @ gs2) |
1556 end | 1566 end |
1557 | L.ECApp (e, c) => | 1567 | L.ECApp (e, c) => |
1558 let | 1568 let |
1559 val (e', et, gs1) = elabExp (env, denv) e | 1569 val (e', et, gs1) = elabExp (env, denv) e |
1560 val (e', et, gs2) = elabHead (env, denv) e' et | 1570 val (e', et, gs2) = elabHead (env, denv) e' et |
1568 val () = checkKind env c' ck k | 1578 val () = checkKind env c' ck k |
1569 val eb' = subConInCon (0, c') eb | 1579 val eb' = subConInCon (0, c') eb |
1570 handle SynUnif => (expError env (Unif ("substitution", eb)); | 1580 handle SynUnif => (expError env (Unif ("substitution", eb)); |
1571 cerror) | 1581 cerror) |
1572 in | 1582 in |
1573 ((L'.ECApp (e', c'), loc), eb', gs1 @ gs2 @ gs3 @ gs4) | 1583 ((L'.ECApp (e', c'), loc), eb', gs1 @ gs2 @ enD gs3 @ enD gs4) |
1574 end | 1584 end |
1575 | 1585 |
1576 | L'.CUnif _ => | 1586 | L'.CUnif _ => |
1577 (expError env (Unif ("application", et)); | 1587 (expError env (Unif ("application", et)); |
1578 (eerror, cerror, [])) | 1588 (eerror, cerror, [])) |
1604 val (e', t, gs4) = elabExp (env, denv') e | 1614 val (e', t, gs4) = elabExp (env, denv') e |
1605 in | 1615 in |
1606 checkKind env c1' k1 (L'.KRecord ku1, loc); | 1616 checkKind env c1' k1 (L'.KRecord ku1, loc); |
1607 checkKind env c2' k2 (L'.KRecord ku2, loc); | 1617 checkKind env c2' k2 (L'.KRecord ku2, loc); |
1608 | 1618 |
1609 (e', (L'.TDisjoint (c1', c2', t), loc), gs1 @ gs2 @ gs3 @ gs4) | 1619 (e', (L'.TDisjoint (c1', c2', t), loc), enD gs1 @ enD gs2 @ enD gs3 @ gs4) |
1610 end | 1620 end |
1611 | 1621 |
1612 | L.ERecord xes => | 1622 | L.ERecord xes => |
1613 let | 1623 let |
1614 val (xes', gs) = ListUtil.foldlMap (fn ((x, e), gs) => | 1624 val (xes', gs) = ListUtil.foldlMap (fn ((x, e), gs) => |
1615 let | 1625 let |
1616 val (x', xk, gs1) = elabCon (env, denv) x | 1626 val (x', xk, gs1) = elabCon (env, denv) x |
1617 val (e', et, gs2) = elabExp (env, denv) e | 1627 val (e', et, gs2) = elabExp (env, denv) e |
1618 in | 1628 in |
1619 checkKind env x' xk kname; | 1629 checkKind env x' xk kname; |
1620 ((x', e', et), gs1 @ gs2 @ gs) | 1630 ((x', e', et), enD gs1 @ gs2 @ gs) |
1621 end) | 1631 end) |
1622 [] xes | 1632 [] xes |
1623 | 1633 |
1624 val k = (L'.KType, loc) | 1634 val k = (L'.KType, loc) |
1625 | 1635 |
1639 end) | 1649 end) |
1640 gs rest | 1650 gs rest |
1641 in | 1651 in |
1642 prove (rest, gs) | 1652 prove (rest, gs) |
1643 end | 1653 end |
1654 | |
1655 val gsD = List.mapPartial (fn Disjoint d => SOME d | _ => NONE) gs | |
1656 val gsO = List.filter (fn Disjoint _ => false | _ => true) gs | |
1644 in | 1657 in |
1645 ((L'.ERecord xes', loc), | 1658 ((L'.ERecord xes', loc), |
1646 (L'.TRecord (L'.CRecord (ktype, map (fn (x', _, et) => (x', et)) xes'), loc), loc), | 1659 (L'.TRecord (L'.CRecord (ktype, map (fn (x', _, et) => (x', et)) xes'), loc), loc), |
1647 prove (xes', gs)) | 1660 enD (prove (xes', gsD)) @ gsO) |
1648 end | 1661 end |
1649 | 1662 |
1650 | L.EField (e, c) => | 1663 | L.EField (e, c) => |
1651 let | 1664 let |
1652 val (e', et, gs1) = elabExp (env, denv) e | 1665 val (e', et, gs1) = elabExp (env, denv) e |
1659 val gs3 = | 1672 val gs3 = |
1660 checkCon (env, denv) e' et | 1673 checkCon (env, denv) e' et |
1661 (L'.TRecord (L'.CConcat (first, rest), loc), loc) | 1674 (L'.TRecord (L'.CConcat (first, rest), loc), loc) |
1662 val gs4 = D.prove env denv (first, rest, loc) | 1675 val gs4 = D.prove env denv (first, rest, loc) |
1663 in | 1676 in |
1664 ((L'.EField (e', c', {field = ft, rest = rest}), loc), ft, gs1 @ gs2 @ gs3 @ gs4) | 1677 ((L'.EField (e', c', {field = ft, rest = rest}), loc), ft, gs1 @ enD gs2 @ enD gs3 @ enD gs4) |
1665 end | 1678 end |
1666 | 1679 |
1667 | L.ECut (e, c) => | 1680 | L.ECut (e, c) => |
1668 let | 1681 let |
1669 val (e', et, gs1) = elabExp (env, denv) e | 1682 val (e', et, gs1) = elabExp (env, denv) e |
1676 val gs3 = | 1689 val gs3 = |
1677 checkCon (env, denv) e' et | 1690 checkCon (env, denv) e' et |
1678 (L'.TRecord (L'.CConcat (first, rest), loc), loc) | 1691 (L'.TRecord (L'.CConcat (first, rest), loc), loc) |
1679 val gs4 = D.prove env denv (first, rest, loc) | 1692 val gs4 = D.prove env denv (first, rest, loc) |
1680 in | 1693 in |
1681 ((L'.ECut (e', c', {field = ft, rest = rest}), loc), (L'.TRecord rest, loc), gs1 @ gs2 @ gs3 @ gs4) | 1694 ((L'.ECut (e', c', {field = ft, rest = rest}), loc), (L'.TRecord rest, loc), |
1695 gs1 @ enD gs2 @ enD gs3 @ enD gs4) | |
1682 end | 1696 end |
1683 | 1697 |
1684 | L.EFold => | 1698 | L.EFold => |
1685 let | 1699 let |
1686 val dom = kunif loc | 1700 val dom = kunif loc |
1699 | 1713 |
1700 val gs1 = checkPatCon (env, denv) p' pt et | 1714 val gs1 = checkPatCon (env, denv) p' pt et |
1701 val (e', et, gs2) = elabExp (env, denv) e | 1715 val (e', et, gs2) = elabExp (env, denv) e |
1702 val gs3 = checkCon (env, denv) e' et result | 1716 val gs3 = checkCon (env, denv) e' et result |
1703 in | 1717 in |
1704 ((p', e'), gs1 @ gs2 @ gs3 @ gs) | 1718 ((p', e'), enD gs1 @ gs2 @ enD gs3 @ gs) |
1705 end) | 1719 end) |
1706 gs1 pes | 1720 gs1 pes |
1707 | 1721 |
1708 val (total, gs') = exhaustive (env, denv, et, map #1 pes') | 1722 val (total, gs') = exhaustive (env, denv, et, map #1 pes') |
1709 in | 1723 in |
1710 if total then | 1724 if total then |
1711 () | 1725 () |
1712 else | 1726 else |
1713 expError env (Inexhaustive loc); | 1727 expError env (Inexhaustive loc); |
1714 | 1728 |
1715 ((L'.ECase (e', pes', {disc = et, result = result}), loc), result, gs' @ gs) | 1729 ((L'.ECase (e', pes', {disc = et, result = result}), loc), result, enD gs' @ gs) |
1716 end | 1730 end |
1717 end | 1731 end |
1718 | 1732 |
1719 | 1733 |
1720 datatype decl_error = | 1734 datatype decl_error = |
2686 end | 2700 end |
2687 | 2701 |
2688 | _ => sgnError env (SgnWrongForm (sgn1, sgn2)) | 2702 | _ => sgnError env (SgnWrongForm (sgn1, sgn2)) |
2689 | 2703 |
2690 | 2704 |
2691 fun elabDecl ((d, loc), (env, denv, gs)) = | 2705 fun elabDecl ((d, loc), (env, denv, gs : constraint list)) = |
2692 case d of | 2706 case d of |
2693 L.DCon (x, ko, c) => | 2707 L.DCon (x, ko, c) => |
2694 let | 2708 let |
2695 val k' = case ko of | 2709 val k' = case ko of |
2696 NONE => kunif loc | 2710 NONE => kunif loc |
2699 val (c', ck, gs') = elabCon (env, denv) c | 2713 val (c', ck, gs') = elabCon (env, denv) c |
2700 val (env', n) = E.pushCNamed env x k' (SOME c') | 2714 val (env', n) = E.pushCNamed env x k' (SOME c') |
2701 in | 2715 in |
2702 checkKind env c' ck k'; | 2716 checkKind env c' ck k'; |
2703 | 2717 |
2704 ([(L'.DCon (x, n, k', c'), loc)], (env', denv, gs' @ gs)) | 2718 ([(L'.DCon (x, n, k', c'), loc)], (env', denv, enD gs' @ gs)) |
2705 end | 2719 end |
2706 | L.DDatatype (x, xs, xcs) => | 2720 | L.DDatatype (x, xs, xcs) => |
2707 let | 2721 let |
2708 val k = (L'.KType, loc) | 2722 val k = (L'.KType, loc) |
2709 val k' = foldl (fn (_, k') => (L'.KArrow (k, k'), loc)) k xs | 2723 val k' = foldl (fn (_, k') => (L'.KArrow (k, k'), loc)) k xs |
2725 | SOME t' => | 2739 | SOME t' => |
2726 let | 2740 let |
2727 val (t', tk, gs') = elabCon (env', denv') t' | 2741 val (t', tk, gs') = elabCon (env', denv') t' |
2728 in | 2742 in |
2729 checkKind env' t' tk k; | 2743 checkKind env' t' tk k; |
2730 (SOME t', (L'.TFun (t', t), loc), gs' @ gs) | 2744 (SOME t', (L'.TFun (t', t), loc), enD gs' @ gs) |
2731 end | 2745 end |
2732 val t = foldr (fn (x, t) => (L'.TCFun (L'.Implicit, x, k, t), loc)) t xs | 2746 val t = foldr (fn (x, t) => (L'.TCFun (L'.Implicit, x, k, t), loc)) t xs |
2733 | 2747 |
2734 val (env, n') = E.pushENamed env x t | 2748 val (env, n') = E.pushENamed env x t |
2735 in | 2749 in |
2760 (strerror, sgnerror)) | 2774 (strerror, sgnerror)) |
2761 | SOME sgn => ((L'.StrProj (str, m), loc), sgn)) | 2775 | SOME sgn => ((L'.StrProj (str, m), loc), sgn)) |
2762 ((L'.StrVar n, loc), sgn) ms | 2776 ((L'.StrVar n, loc), sgn) ms |
2763 in | 2777 in |
2764 case hnormCon (env, denv) (L'.CModProj (n, ms, s), loc) of | 2778 case hnormCon (env, denv) (L'.CModProj (n, ms, s), loc) of |
2765 ((L'.CModProj (n, ms, s), _), gs) => | 2779 ((L'.CModProj (n, ms, s), _), gs') => |
2766 (case E.projectDatatype env {sgn = sgn, str = str, field = s} of | 2780 (case E.projectDatatype env {sgn = sgn, str = str, field = s} of |
2767 NONE => (conError env (UnboundDatatype (loc, s)); | 2781 NONE => (conError env (UnboundDatatype (loc, s)); |
2768 ([], (env, denv, gs))) | 2782 ([], (env, denv, gs))) |
2769 | SOME (xs, xncs) => | 2783 | SOME (xs, xncs) => |
2770 let | 2784 let |
2786 t xs | 2800 t xs |
2787 in | 2801 in |
2788 E.pushENamedAs env x n t | 2802 E.pushENamedAs env x n t |
2789 end) env xncs | 2803 end) env xncs |
2790 in | 2804 in |
2791 ([(L'.DDatatypeImp (x, n', n, ms, s, xs, xncs), loc)], (env, denv, gs)) | 2805 ([(L'.DDatatypeImp (x, n', n, ms, s, xs, xncs), loc)], (env, denv, enD gs' @ gs)) |
2792 end) | 2806 end) |
2793 | _ => (strError env (NotDatatype loc); | 2807 | _ => (strError env (NotDatatype loc); |
2794 ([], (env, denv, []))) | 2808 ([], (env, denv, []))) |
2795 end) | 2809 end) |
2796 | 2810 |
2805 val (c', gs4) = normClassConstraint (env, denv) c' | 2819 val (c', gs4) = normClassConstraint (env, denv) c' |
2806 val (env', n) = E.pushENamed env x c' | 2820 val (env', n) = E.pushENamed env x c' |
2807 in | 2821 in |
2808 (*prefaces "DVal" [("x", Print.PD.string x), | 2822 (*prefaces "DVal" [("x", Print.PD.string x), |
2809 ("c'", p_con env c')];*) | 2823 ("c'", p_con env c')];*) |
2810 ([(L'.DVal (x, n, c', e'), loc)], (env', denv, gs1 @ gs2 @ gs3 @ gs4 @ gs)) | 2824 ([(L'.DVal (x, n, c', e'), loc)], (env', denv, enD gs1 @ gs2 @ enD gs3 @ enD gs4 @ gs)) |
2811 end | 2825 end |
2812 | L.DValRec vis => | 2826 | L.DValRec vis => |
2813 let | 2827 let |
2814 val (vis, gs) = ListUtil.foldlMap | 2828 val (vis, gs) = ListUtil.foldlMap |
2815 (fn ((x, co, e), gs) => | 2829 (fn ((x, co, e), gs) => |
2816 let | 2830 let |
2817 val (c', _, gs1) = case co of | 2831 val (c', _, gs1) = case co of |
2818 NONE => (cunif (loc, ktype), ktype, []) | 2832 NONE => (cunif (loc, ktype), ktype, []) |
2819 | SOME c => elabCon (env, denv) c | 2833 | SOME c => elabCon (env, denv) c |
2820 in | 2834 in |
2821 ((x, c', e), gs1 @ gs) | 2835 ((x, c', e), enD gs1 @ gs) |
2822 end) [] vis | 2836 end) [] vis |
2823 | 2837 |
2824 val (vis, env) = ListUtil.foldlMap (fn ((x, c', e), env) => | 2838 val (vis, env) = ListUtil.foldlMap (fn ((x, c', e), env) => |
2825 let | 2839 let |
2826 val (env, n) = E.pushENamed env x c' | 2840 val (env, n) = E.pushENamed env x c' |
2832 let | 2846 let |
2833 val (e', et, gs1) = elabExp (env, denv) e | 2847 val (e', et, gs1) = elabExp (env, denv) e |
2834 | 2848 |
2835 val gs2 = checkCon (env, denv) e' et c' | 2849 val gs2 = checkCon (env, denv) e' et c' |
2836 in | 2850 in |
2837 ((x, n, c', e'), gs1 @ gs2 @ gs) | 2851 ((x, n, c', e'), gs1 @ enD gs2 @ gs) |
2838 end) gs vis | 2852 end) gs vis |
2839 in | 2853 in |
2840 ([(L'.DValRec vis, loc)], (env, denv, gs)) | 2854 ([(L'.DValRec vis, loc)], (env, denv, gs)) |
2841 end | 2855 end |
2842 | 2856 |
2843 | L.DSgn (x, sgn) => | 2857 | L.DSgn (x, sgn) => |
2844 let | 2858 let |
2845 val (sgn', gs') = elabSgn (env, denv) sgn | 2859 val (sgn', gs') = elabSgn (env, denv) sgn |
2846 val (env', n) = E.pushSgnNamed env x sgn' | 2860 val (env', n) = E.pushSgnNamed env x sgn' |
2847 in | 2861 in |
2848 ([(L'.DSgn (x, n, sgn'), loc)], (env', denv, gs' @ gs)) | 2862 ([(L'.DSgn (x, n, sgn'), loc)], (env', denv, enD gs' @ gs)) |
2849 end | 2863 end |
2850 | 2864 |
2851 | L.DStr (x, sgno, str) => | 2865 | L.DStr (x, sgno, str) => |
2852 let | 2866 let |
2853 val () = if x = "Basis" then | 2867 val () = if x = "Basis" then |
2904 | _ => str | 2918 | _ => str |
2905 | 2919 |
2906 val (str', actual, gs2) = elabStr (env, denv) str | 2920 val (str', actual, gs2) = elabStr (env, denv) str |
2907 in | 2921 in |
2908 subSgn (env, denv) (selfifyAt env {str = str', sgn = actual}) formal; | 2922 subSgn (env, denv) (selfifyAt env {str = str', sgn = actual}) formal; |
2909 (str', formal, gs1 @ gs2) | 2923 (str', formal, enD gs1 @ gs2) |
2910 end | 2924 end |
2911 | 2925 |
2912 val (env', n) = E.pushStrNamed env x sgn' | 2926 val (env', n) = E.pushStrNamed env x sgn' |
2913 in | 2927 in |
2914 case #1 (hnormSgn env sgn') of | 2928 case #1 (hnormSgn env sgn') of |
2925 let | 2939 let |
2926 val (sgn', gs') = elabSgn (env, denv) sgn | 2940 val (sgn', gs') = elabSgn (env, denv) sgn |
2927 | 2941 |
2928 val (env', n) = E.pushStrNamed env x sgn' | 2942 val (env', n) = E.pushStrNamed env x sgn' |
2929 in | 2943 in |
2930 ([(L'.DFfiStr (x, n, sgn'), loc)], (env', denv, gs' @ gs)) | 2944 ([(L'.DFfiStr (x, n, sgn'), loc)], (env', denv, enD gs' @ gs)) |
2931 end | 2945 end |
2932 | 2946 |
2933 | L.DOpen (m, ms) => | 2947 | L.DOpen (m, ms) => |
2934 (case E.lookupStr env m of | 2948 (case E.lookupStr env m of |
2935 NONE => (strError env (UnboundStr (loc, m)); | 2949 NONE => (strError env (UnboundStr (loc, m)); |
2958 val (denv', gs4) = D.assert env denv (c1', c2') | 2972 val (denv', gs4) = D.assert env denv (c1', c2') |
2959 in | 2973 in |
2960 checkKind env c1' k1 (L'.KRecord (kunif loc), loc); | 2974 checkKind env c1' k1 (L'.KRecord (kunif loc), loc); |
2961 checkKind env c2' k2 (L'.KRecord (kunif loc), loc); | 2975 checkKind env c2' k2 (L'.KRecord (kunif loc), loc); |
2962 | 2976 |
2963 ([(L'.DConstraint (c1', c2'), loc)], (env, denv', gs1 @ gs2 @ gs3 @ gs4 @ gs)) | 2977 ([(L'.DConstraint (c1', c2'), loc)], (env, denv', enD gs1 @ enD gs2 @ enD gs3 @ enD gs4 @ gs)) |
2964 end | 2978 end |
2965 | 2979 |
2966 | L.DOpenConstraints (m, ms) => | 2980 | L.DOpenConstraints (m, ms) => |
2967 let | 2981 let |
2968 val denv = dopenConstraints (loc, env, denv) {str = m, strs = ms} | 2982 val denv = dopenConstraints (loc, env, denv) {str = m, strs = ms} |
3025 let | 3039 let |
3026 val (c', k, gs') = elabCon (env, denv) c | 3040 val (c', k, gs') = elabCon (env, denv) c |
3027 val (env, n) = E.pushENamed env x (L'.CApp (tableOf (), c'), loc) | 3041 val (env, n) = E.pushENamed env x (L'.CApp (tableOf (), c'), loc) |
3028 in | 3042 in |
3029 checkKind env c' k (L'.KRecord (L'.KType, loc), loc); | 3043 checkKind env c' k (L'.KRecord (L'.KType, loc), loc); |
3030 ([(L'.DTable (!basis_r, x, n, c'), loc)], (env, denv, gs' @ gs)) | 3044 ([(L'.DTable (!basis_r, x, n, c'), loc)], (env, denv, enD gs' @ gs)) |
3031 end | 3045 end |
3032 | 3046 |
3033 | L.DClass (x, c) => | 3047 | L.DClass (x, c) => |
3034 let | 3048 let |
3035 val k = (L'.KArrow ((L'.KType, loc), (L'.KType, loc)), loc) | 3049 val k = (L'.KArrow ((L'.KType, loc), (L'.KType, loc)), loc) |
3203 (ran', gs) | 3217 (ran', gs) |
3204 end | 3218 end |
3205 in | 3219 in |
3206 ((L'.StrFun (m, n, dom', formal, str'), loc), | 3220 ((L'.StrFun (m, n, dom', formal, str'), loc), |
3207 (L'.SgnFun (m, n, dom', formal), loc), | 3221 (L'.SgnFun (m, n, dom', formal), loc), |
3208 gs1 @ gs2 @ gs3) | 3222 enD gs1 @ gs2 @ enD gs3) |
3209 end | 3223 end |
3210 | L.StrApp (str1, str2) => | 3224 | L.StrApp (str1, str2) => |
3211 let | 3225 let |
3212 val (str1', sgn1, gs1) = elabStr (env, denv) str1 | 3226 val (str1', sgn1, gs1) = elabStr (env, denv) str1 |
3213 val (str2', sgn2, gs2) = elabStr (env, denv) str2 | 3227 val (str2', sgn2, gs2) = elabStr (env, denv) str2 |
3280 val (file, (_, gs)) = ListUtil.foldlMapConcat elabDecl' (env', []) file | 3294 val (file, (_, gs)) = ListUtil.foldlMapConcat elabDecl' (env', []) file |
3281 in | 3295 in |
3282 if ErrorMsg.anyErrors () then | 3296 if ErrorMsg.anyErrors () then |
3283 () | 3297 () |
3284 else | 3298 else |
3285 app (fn (loc, env, denv, c1, c2) => | 3299 app (fn Disjoint (loc, env, denv, c1, c2) => |
3286 case D.prove env denv (c1, c2, loc) of | 3300 (case D.prove env denv (c1, c2, loc) of |
3287 [] => () | 3301 [] => () |
3288 | _ => | 3302 | _ => |
3289 (ErrorMsg.errorAt loc "Couldn't prove field name disjointness"; | 3303 (ErrorMsg.errorAt loc "Couldn't prove field name disjointness"; |
3290 eprefaces' [("Con 1", p_con env c1), | 3304 eprefaces' [("Con 1", p_con env c1), |
3291 ("Con 2", p_con env c2), | 3305 ("Con 2", p_con env c2), |
3292 ("Hnormed 1", p_con env (ElabOps.hnormCon env c1)), | 3306 ("Hnormed 1", p_con env (ElabOps.hnormCon env c1)), |
3293 ("Hnormed 2", p_con env (ElabOps.hnormCon env c2))])) gs; | 3307 ("Hnormed 2", p_con env (ElabOps.hnormCon env c2))])) |
3308 | TypeClass (env, c, r, loc) => | |
3309 case E.resolveClass env c of | |
3310 SOME e => r := SOME e | |
3311 | NONE => expError env (Unresolvable (loc, c))) gs; | |
3294 | 3312 |
3295 (L'.DFfiStr ("Basis", basis_n, sgn), ErrorMsg.dummySpan) :: ds @ file | 3313 (L'.DFfiStr ("Basis", basis_n, sgn), ErrorMsg.dummySpan) :: ds @ file |
3296 end | 3314 end |
3297 | 3315 |
3298 end | 3316 end |