244 let |
244 let |
245 fun gen cs _ (Const (_, T)) tye_idx = (T, tye_idx, cs) |
245 fun gen cs _ (Const (_, T)) tye_idx = (T, tye_idx, cs) |
246 | gen cs _ (Free (_, T)) tye_idx = (T, tye_idx, cs) |
246 | gen cs _ (Free (_, T)) tye_idx = (T, tye_idx, cs) |
247 | gen cs _ (Var (_, T)) tye_idx = (T, tye_idx, cs) |
247 | gen cs _ (Var (_, T)) tye_idx = (T, tye_idx, cs) |
248 | gen cs bs (Bound i) tye_idx = |
248 | gen cs bs (Bound i) tye_idx = |
249 (snd (nth bs i handle Subscript => err_loose i), tye_idx, cs) |
249 (snd (nth bs i handle General.Subscript => err_loose i), tye_idx, cs) |
250 | gen cs bs (Abs (x, T, t)) tye_idx = |
250 | gen cs bs (Abs (x, T, t)) tye_idx = |
251 let val (U, tye_idx', cs') = gen cs ((x, T) :: bs) t tye_idx |
251 let val (U, tye_idx', cs') = gen cs ((x, T) :: bs) t tye_idx |
252 in (T --> U, tye_idx', cs') end |
252 in (T --> U, tye_idx', cs') end |
253 | gen cs bs (t $ u) tye_idx = |
253 | gen cs bs (t $ u) tye_idx = |
254 let |
254 let |
634 in (Free (x, T'), T') end |
634 in (Free (x, T'), T') end |
635 | insert _ (Var (xi, T)) = |
635 | insert _ (Var (xi, T)) = |
636 let val T' = T; |
636 let val T' = T; |
637 in (Var (xi, T'), T') end |
637 in (Var (xi, T'), T') end |
638 | insert bs (Bound i) = |
638 | insert bs (Bound i) = |
639 let val T = nth bs i handle Subscript => err_loose i; |
639 let val T = nth bs i handle General.Subscript => err_loose i; |
640 in (Bound i, T) end |
640 in (Bound i, T) end |
641 | insert bs (Abs (x, T, t)) = |
641 | insert bs (Abs (x, T, t)) = |
642 let |
642 let |
643 val T' = T; |
643 val T' = T; |
644 val (t', T'') = insert (T' :: bs) t; |
644 val (t', T'') = insert (T' :: bs) t; |
669 |
669 |
670 fun inf _ (t as (Const (_, T))) tye_idx = (t, T, tye_idx) |
670 fun inf _ (t as (Const (_, T))) tye_idx = (t, T, tye_idx) |
671 | inf _ (t as (Free (_, T))) tye_idx = (t, T, tye_idx) |
671 | inf _ (t as (Free (_, T))) tye_idx = (t, T, tye_idx) |
672 | inf _ (t as (Var (_, T))) tye_idx = (t, T, tye_idx) |
672 | inf _ (t as (Var (_, T))) tye_idx = (t, T, tye_idx) |
673 | inf bs (t as (Bound i)) tye_idx = |
673 | inf bs (t as (Bound i)) tye_idx = |
674 (t, snd (nth bs i handle Subscript => err_loose i), tye_idx) |
674 (t, snd (nth bs i handle General.Subscript => err_loose i), tye_idx) |
675 | inf bs (Abs (x, T, t)) tye_idx = |
675 | inf bs (Abs (x, T, t)) tye_idx = |
676 let val (t', U, tye_idx') = inf ((x, T) :: bs) t tye_idx |
676 let val (t', U, tye_idx') = inf ((x, T) :: bs) t tye_idx |
677 in (Abs (x, T, t'), T --> U, tye_idx') end |
677 in (Abs (x, T, t'), T --> U, tye_idx') end |
678 | inf bs (t $ u) tye_idx = |
678 | inf bs (t $ u) tye_idx = |
679 let |
679 let |