@@ -22,9 +22,15 @@ instance Monad TC where
22 Error e -> Error e
22 Error e -> Error e
23 fail = Error
23 fail = Error
25+instance MonadPlus TC where
26+ mzero = Error "Unknown error"
27+ (OK x) `mplus` _ = OK x
28+ _ `mplus` (OK y) = OK y
25converts :: Context -> Env -> Term -> Term -> TC ()
31converts :: Context -> Env -> Term -> Term -> TC ()
26−converts ctxt env x y = if (normalise ctxt (bindEnv env x) ==
32+converts ctxt env x y = if (normalise ctxt env (bindEnv env x) ==
27− normalise ctxt (bindEnv env y))
33+ normalise ctxt env (bindEnv env y))
28 then return ()
34 then return ()
29 else fail ("Can't convert between " ++
35 else fail ("Can't convert between " ++
30 show x ++ " and " ++ show y)
36 show x ++ " and " ++ show y)
@@ -41,12 +47,12 @@ check ctxt env (Var n)
41check ctxt env (RApp f a)
47check ctxt env (RApp f a)
42 = do (fv, fty) <- check ctxt env f
48 = do (fv, fty) <- check ctxt env f
43 (av, aty) <- check ctxt env a
49 (av, aty) <- check ctxt env a
44− let fty' = normalise ctxt fty
50+ let fty' = normalise ctxt env fty
45 case fty' of
51 case fty' of
46 Bind x (Pi s) t ->
52 Bind x (Pi s) t ->
47 do converts ctxt env s aty
53 do converts ctxt env s aty
48 return (App fv fty av,
54 return (App fv fty av,
49− normalise ctxt (Bind x (Let av aty) t))
55+ normalise ctxt env (Bind x (Let av aty) t))
50 t -> fail "Can't apply a non-function type"
56 t -> fail "Can't apply a non-function type"
51check ctxt env (RSet i) = return (Set i, Set (i+1))
57check ctxt env (RSet i) = return (Set i, Set (i+1))
52check ctxt env (RBind n b sc)
58check ctxt env (RBind n b sc)
@@ -55,42 +61,42 @@ check ctxt env (RBind n b sc)
55 discharge n b' scv sct
61 discharge n b' scv sct
56 where checkBinder (Lam t)
62 where checkBinder (Lam t)
57 = do (tv, tt) <- check ctxt env t
63 = do (tv, tt) <- check ctxt env t
58− let tv' = normalise ctxt tv
64+ let tv' = normalise ctxt env tv
59− let tt' = normalise ctxt tt
65+ let tt' = normalise ctxt env tt
61 return (Lam tv')
67 return (Lam tv')
62 checkBinder (Pi t)
68 checkBinder (Pi t)
63 = do (tv, tt) <- check ctxt env t
69 = do (tv, tt) <- check ctxt env t
64− let tv' = normalise ctxt tv
70+ let tv' = normalise ctxt env tv
65− let tt' = normalise ctxt tt
71+ let tt' = normalise ctxt env tt
67 return (Pi tv')
73 return (Pi tv')
68 checkBinder (Let t v)
74 checkBinder (Let t v)
69 = do (tv, tt) <- check ctxt env t
75 = do (tv, tt) <- check ctxt env t
70 (vv, vt) <- check ctxt env v
76 (vv, vt) <- check ctxt env v
71− let tv' = normalise ctxt tv
77+ let tv' = normalise ctxt env tv
72− let tt' = normalise ctxt tt
78+ let tt' = normalise ctxt env tt
73 converts ctxt env tv vt
79 converts ctxt env tv vt
75 return (Let tv' vv)
81 return (Let tv' vv)
76 checkBinder (Hole t)
82 checkBinder (Hole t)
77 = do (tv, tt) <- check ctxt env t
83 = do (tv, tt) <- check ctxt env t
78− let tv' = normalise ctxt tv
84+ let tv' = normalise ctxt env tv
79− let tt' = normalise ctxt tt
85+ let tt' = normalise ctxt env tt
81 return (Hole tv')
87 return (Hole tv')
82 checkBinder (Guess t v)
88 checkBinder (Guess t v)
83 = do (tv, tt) <- check ctxt env t
89 = do (tv, tt) <- check ctxt env t
84 (vv, vt) <- check ctxt env v
90 (vv, vt) <- check ctxt env v
85− let tv' = normalise ctxt tv
91+ let tv' = normalise ctxt env tv
86− let tt' = normalise ctxt tt
92+ let tt' = normalise ctxt env tt
87 converts ctxt env tv vt
93 converts ctxt env tv vt
89 return (Guess tv' vv)
95 return (Guess tv' vv)
90 checkBinder (PVar t)
96 checkBinder (PVar t)
91 = do (tv, tt) <- check ctxt env t
97 = do (tv, tt) <- check ctxt env t
92− let tv' = normalise ctxt tv
98+ let tv' = normalise ctxt env tv
93− let tt' = normalise ctxt tt
99+ let tt' = normalise ctxt env tt
94 isSet tt'
100 isSet tt'
95 return (PVar tv')
101 return (PVar tv')
@@ -131,4 +137,4 @@ checkProgram ctxt ((n, RFunction (RawFun ty val)):xs)
131 isSet tyt'
137 isSet tyt'
132 converts ctxt [] ty' valt'
138 converts ctxt [] ty' valt'
133 checkProgram ((n, Function (Fun ty' (hoas [] ty')
139 checkProgram ((n, Function (Fun ty' (hoas [] ty')
134− val' (hoas [] val'))):ctxt) xs
140+ val' (hoas [] val'))):ctxt) xs