|
@ -42,6 +42,30 @@ applProj fun PProj2 = vProj2 fun |
|
|
force :: Value -> Value |
|
|
force :: Value -> Value |
|
|
force = unsafePerformIO . forceIO |
|
|
force = unsafePerformIO . forceIO |
|
|
|
|
|
|
|
|
|
|
|
-- everywhere force |
|
|
|
|
|
zonkIO :: Value -> IO Value |
|
|
|
|
|
zonkIO (VNe hd sp) = do |
|
|
|
|
|
sp' <- traverse zonkSp sp |
|
|
|
|
|
case hd of |
|
|
|
|
|
HMeta (MV _ cell) -> do |
|
|
|
|
|
solved <- liftIO $ readIORef cell |
|
|
|
|
|
case solved of |
|
|
|
|
|
Just vl -> zonkIO $ foldl applProj vl (reverse sp') |
|
|
|
|
|
Nothing -> pure $ VNe hd sp' |
|
|
|
|
|
hd -> pure $ VNe hd sp' |
|
|
|
|
|
where |
|
|
|
|
|
zonkSp (PApp p x) = PApp p <$> zonkIO x |
|
|
|
|
|
zonkSp PProj1 = pure PProj1 |
|
|
|
|
|
zonkSp PProj2 = pure PProj2 |
|
|
|
|
|
zonkIO (VLam p (Closure s k)) = pure $ VLam p (Closure s (zonk . k)) |
|
|
|
|
|
zonkIO (VPi p d (Closure s k)) = VPi p <$> zonkIO d <*> pure (Closure s (zonk . k)) |
|
|
|
|
|
zonkIO (VSigma d (Closure s k)) = VSigma <$> zonkIO d <*> pure (Closure s (zonk . k)) |
|
|
|
|
|
zonkIO (VPair a b) = VPair <$> zonkIO a <*> zonkIO b |
|
|
|
|
|
zonkIO VType = pure VType |
|
|
|
|
|
|
|
|
|
|
|
zonk :: Value -> Value |
|
|
|
|
|
zonk = unsafePerformIO . zonkIO |
|
|
|
|
|
|
|
|
evalWithEnv :: ElabEnv -> Term -> Value |
|
|
evalWithEnv :: ElabEnv -> Term -> Value |
|
|
evalWithEnv env (Ref x) = |
|
|
evalWithEnv env (Ref x) = |
|
|
case Map.lookup x (getEnv env) of |
|
|
case Map.lookup x (getEnv env) of |
|
@ -51,17 +75,17 @@ evalWithEnv env (App p f x) = vApp p (evalWithEnv env f) (evalWithEnv env x) |
|
|
|
|
|
|
|
|
evalWithEnv env (Lam p s t) = |
|
|
evalWithEnv env (Lam p s t) = |
|
|
VLam p $ Closure s $ \a -> |
|
|
VLam p $ Closure s $ \a -> |
|
|
evalWithEnv (ElabEnv (Map.insert (Bound s) (error "type of abs", a) (getEnv env))) t |
|
|
|
|
|
|
|
|
evalWithEnv env { getEnv = Map.insert (Bound s) (error "type of abs", a) (getEnv env) } t |
|
|
|
|
|
|
|
|
evalWithEnv env (Pi p s d t) = |
|
|
evalWithEnv env (Pi p s d t) = |
|
|
VPi p (evalWithEnv env d) $ Closure s $ \a -> |
|
|
VPi p (evalWithEnv env d) $ Closure s $ \a -> |
|
|
evalWithEnv (ElabEnv (Map.insert (Bound s) (error "type of abs", a) (getEnv env))) t |
|
|
|
|
|
|
|
|
evalWithEnv env { getEnv = (Map.insert (Bound s) (error "type of abs", a) (getEnv env))} t |
|
|
|
|
|
|
|
|
evalWithEnv _ (Meta m) = VNe (HMeta m) [] |
|
|
evalWithEnv _ (Meta m) = VNe (HMeta m) [] |
|
|
|
|
|
|
|
|
evalWithEnv env (Sigma s d t) = |
|
|
evalWithEnv env (Sigma s d t) = |
|
|
VSigma (evalWithEnv env d) $ Closure s $ \a -> |
|
|
VSigma (evalWithEnv env d) $ Closure s $ \a -> |
|
|
evalWithEnv (ElabEnv (Map.insert (Bound s) (error "type of abs", a) (getEnv env))) t |
|
|
|
|
|
|
|
|
evalWithEnv env { getEnv = Map.insert (Bound s) (error "type of abs", a) (getEnv env) } t |
|
|
|
|
|
|
|
|
evalWithEnv e (Pair a b) = VPair (evalWithEnv e a) (evalWithEnv e b) |
|
|
evalWithEnv e (Pair a b) = VPair (evalWithEnv e a) (evalWithEnv e b) |
|
|
|
|
|
|
|
@ -91,6 +115,7 @@ data NotEqual = NotEqual Value Value |
|
|
unify :: Value -> Value -> ElabM () |
|
|
unify :: Value -> Value -> ElabM () |
|
|
unify topa topb = join $ go <$> forceIO topa <*> forceIO topb where |
|
|
unify topa topb = join $ go <$> forceIO topa <*> forceIO topb where |
|
|
go (VNe (HMeta mv) sp) rhs = solveMeta mv sp rhs |
|
|
go (VNe (HMeta mv) sp) rhs = solveMeta mv sp rhs |
|
|
|
|
|
go rhs (VNe (HMeta mv) sp) = solveMeta mv sp rhs |
|
|
|
|
|
|
|
|
go (VNe x a) (VNe x' a') |
|
|
go (VNe x a) (VNe x' a') |
|
|
| x == x', length a == length a' = |
|
|
| x == x', length a == length a' = |
|
@ -118,12 +143,18 @@ unify topa topb = join $ go <$> forceIO topa <*> forceIO topb where |
|
|
unify d d' |
|
|
unify d d' |
|
|
unify (k t) (k' t) |
|
|
unify (k t) (k' t) |
|
|
|
|
|
|
|
|
|
|
|
go VType VType = pure () |
|
|
|
|
|
|
|
|
go _ _ = fail |
|
|
go _ _ = fail |
|
|
|
|
|
|
|
|
fail = liftIO . throwIO $ NotEqual topa topb |
|
|
fail = liftIO . throwIO $ NotEqual topa topb |
|
|
|
|
|
|
|
|
unifySpine (PApp a v) (PApp a' v') |
|
|
unifySpine (PApp a v) (PApp a' v') |
|
|
| a == a' = unify v v' |
|
|
| a == a' = unify v v' |
|
|
|
|
|
|
|
|
|
|
|
unifySpine PProj1 PProj1 = pure () |
|
|
|
|
|
unifySpine PProj2 PProj2 = pure () |
|
|
|
|
|
|
|
|
unifySpine _ _ = fail |
|
|
unifySpine _ _ = fail |
|
|
|
|
|
|
|
|
isConvertibleTo :: Value -> Value -> ElabM (Term -> Term) |
|
|
isConvertibleTo :: Value -> Value -> ElabM (Term -> Term) |
|
@ -143,9 +174,9 @@ newMeta _dom = do |
|
|
|
|
|
|
|
|
env <- asks getEnv |
|
|
env <- asks getEnv |
|
|
|
|
|
|
|
|
t <- for (Map.toList env) $ \(n, (_, c)) -> pure $ |
|
|
|
|
|
case c of |
|
|
|
|
|
VVar n' | n == n' -> Just (PApp Ex (VVar n')) |
|
|
|
|
|
|
|
|
t <- for (Map.toList env) $ \(n, _) -> pure $ |
|
|
|
|
|
case n of |
|
|
|
|
|
Bound{} -> Just (PApp Ex (VVar n)) |
|
|
_ -> Nothing |
|
|
_ -> Nothing |
|
|
|
|
|
|
|
|
pure (VNe (HMeta m) (catMaybes t)) |
|
|
pure (VNe (HMeta m) (catMaybes t)) |
|
@ -161,11 +192,12 @@ _nameCounter = unsafePerformIO $ newIORef 0 |
|
|
|
|
|
|
|
|
solveMeta :: MV -> [Projection] -> Value -> ElabM () |
|
|
solveMeta :: MV -> [Projection] -> Value -> ElabM () |
|
|
solveMeta m@(MV _ cell) sp rhs = do |
|
|
solveMeta m@(MV _ cell) sp rhs = do |
|
|
|
|
|
env <- ask |
|
|
liftIO $ print (m, sp, rhs) |
|
|
liftIO $ print (m, sp, rhs) |
|
|
names <- checkSpine Set.empty sp |
|
|
names <- checkSpine Set.empty sp |
|
|
checkScope (Set.fromList (Bound <$> names)) rhs |
|
|
checkScope (Set.fromList (Bound <$> names)) rhs |
|
|
let tm = quote rhs |
|
|
let tm = quote rhs |
|
|
lam = evalWithEnv emptyEnv $ foldr (Lam Ex) tm names |
|
|
|
|
|
|
|
|
lam = evalWithEnv env $ foldr (Lam Ex) tm names |
|
|
liftIO . atomicModifyIORef' cell $ \case |
|
|
liftIO . atomicModifyIORef' cell $ \case |
|
|
Just _ -> error "filled cell in solvedMeta" |
|
|
Just _ -> error "filled cell in solvedMeta" |
|
|
Nothing -> (Just lam, ()) |
|
|
Nothing -> (Just lam, ()) |
|
@ -174,9 +206,10 @@ checkScope :: Set Name -> Value -> ElabM () |
|
|
checkScope scope (VNe h sp) = |
|
|
checkScope scope (VNe h sp) = |
|
|
do |
|
|
do |
|
|
case h of |
|
|
case h of |
|
|
HVar v -> |
|
|
|
|
|
|
|
|
HVar v@Bound{} -> |
|
|
unless (v `Set.member` scope) . liftIO . throwIO $ |
|
|
unless (v `Set.member` scope) . liftIO . throwIO $ |
|
|
NotInScope v |
|
|
NotInScope v |
|
|
|
|
|
HVar{} -> pure () |
|
|
HMeta{} -> pure () |
|
|
HMeta{} -> pure () |
|
|
traverse_ checkProj sp |
|
|
traverse_ checkProj sp |
|
|
where |
|
|
where |
|
|