1{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
5import Control.Monad.State
12 | Error String -- TMP! Make this an informative data structure
15-- at some point, this instance should also carry type checking options
18instance Monad TC where
25instance MonadPlus TC where
26 mzero = Error "Unknown error"
27 (OK x) `mplus` _ = OK x
28 _ `mplus` (OK y) = OK y
31converts :: Context -> Env -> Term -> Term -> TC ()
32converts ctxt env x y = if (normalise ctxt env (bindEnv env x) ==
33 normalise ctxt env (bindEnv env y))
35 else fail ("Can't convert between " ++
36 show x ++ " and " ++ show y)
39isSet (Set _) = return ()
40isSet tm = fail (show tm ++ " is not a Set")
42check :: Context -> Env -> Raw -> TC (Term, Type)
44 | Just (i, ty) <- lookupTyEnv n env = return (V i, ty)
45 | Just (P nt n' ty) <- lookupP n ctxt = return (P nt n' ty, ty)
46 | otherwise = do fail $ "No such variable " ++ show n
47check ctxt env (RApp f a)
48 = do (fv, fty) <- check ctxt env f
49 (av, aty) <- check ctxt env a
50 let fty' = normalise ctxt env fty
53 do converts ctxt env s aty
54 return (App fv fty av,
55 normalise ctxt env (Bind x (Let av aty) t))
56 t -> fail "Can't apply a non-function type"
57check ctxt env (RSet i) = return (Set i, Set (i+1))
58check ctxt env (RBind n b sc)
59 = do b' <- checkBinder b
60 (scv, sct) <- check ctxt ((n, b'):env) sc
61 discharge n b' scv sct
62 where checkBinder (Lam t)
63 = do (tv, tt) <- check ctxt env t
64 let tv' = normalise ctxt env tv
65 let tt' = normalise ctxt env tt
69 = do (tv, tt) <- check ctxt env t
70 let tv' = normalise ctxt env tv
71 let tt' = normalise ctxt env tt
75 = do (tv, tt) <- check ctxt env t
76 (vv, vt) <- check ctxt env v
77 let tv' = normalise ctxt env tv
78 let tt' = normalise ctxt env tt
79 converts ctxt env tv vt
83 = do (tv, tt) <- check ctxt env t
84 let tv' = normalise ctxt env tv
85 let tt' = normalise ctxt env tt
88 checkBinder (Guess t v)
89 = do (tv, tt) <- check ctxt env t
90 (vv, vt) <- check ctxt env v
91 let tv' = normalise ctxt env tv
92 let tt' = normalise ctxt env tt
93 converts ctxt env tv vt
97 = do (tv, tt) <- check ctxt env t
98 let tv' = normalise ctxt env tv
99 let tt' = normalise ctxt env tt
103 discharge n (Lam t) scv sct
104 = return (Bind n (Lam t) scv, Bind n (Pi t) sct)
105 discharge n (Pi t) scv sct
106 = return (Bind n (Pi t) scv, sct)
107 discharge n (Let t v) scv sct
108 = return (Bind n (Let t v) scv, Bind n (Let t v) sct)
109 discharge n (Hole t) scv sct
110 = do -- A hole can't appear in the type of its scope
112 return (Bind n (Hole t) scv, sct)
113 discharge n (Guess t v) scv sct
114 = do -- A hole can't appear in the type of its scope
116 return (Bind n (Guess t v) scv, sct)
117 discharge n (PVar t) scv sct
118 = return (Bind n (PVar t) scv, sct)
120 checkNotHoley i (V v)
121 | v == i = fail "You can't put a hole where a hole don't belong"
122 checkNotHoley i (App f t a) = do checkNotHoley i f
125 checkNotHoley i (Bind n b sc) = checkNotHoley (i+1) sc
126 checkNotHoley _ _ = return ()
128checkProgram :: Context -> RProgram -> TC Context
129checkProgram ctxt [] = return ctxt
130checkProgram ctxt ((n, RConst t):xs)
131 = do (t', tt') <- trace (show n) $ check ctxt [] t
133 checkProgram ((n, Constant Ref t' (hoas [] t')):ctxt) xs
134checkProgram ctxt ((n, RFunction (RawFun ty val)):xs)
135 = do (ty', tyt') <- trace (show n) $ check ctxt [] ty
136 (val', valt') <- check ctxt [] val
138 converts ctxt [] ty' valt'
139 checkProgram ((n, Function (Fun ty' (hoas [] ty')
140 val' (hoas [] val'))):ctxt) xs
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list