This commit is contained in:
Martin Fredin 2023-03-28 15:33:03 +02:00
parent 133cc31e77
commit 76b1c55065
2 changed files with 25 additions and 15 deletions

View file

@ -3,9 +3,14 @@ data forall a. List (a) where {
Cons : a -> List (a) -> List (a) Cons : a -> List (a) -> List (a)
}; };
length : forall c. List (c) -> Int; length : List (Int) -> Int;
length = \list. case list of { length = \list. case list of {
Cons x xs => 1 + length xs; Cons x xs => 1 + length xs;
-- Nil => 0; -- Nil => 0;
-- Cons x (Cons y Nil) => 2; -- Cons x (Cons y Nil) => 2;
}; };

View file

@ -246,6 +246,8 @@ subtype t1 t2 = case (t1, t2) of
, t1:t1s <- typs1 , t1:t1s <- typs1
, t2:t2s <- typs2 , t2:t2s <- typs2
-> do -> do
traceT "t1" (TData name1 typs1)
traceT "t2" (TData name2 typs2)
subtype t1 t2 subtype t1 t2
zipWithM_ go t1s t2s zipWithM_ go t1s t2s
where where
@ -574,17 +576,21 @@ checkPattern patt t_patt = (, t_patt) <$> case patt of
-- Γ ⊢ B₁ → ‥ → Bₘ₊₁ <: A₁ + ‥ + Aₙ ⊣ Θ₁ Θₘ ⊢ pₘ ↑ [Θₘ₋₁]Bₘ ⊣ Δ -- Γ ⊢ B₁ → ‥ → Bₘ₊₁ <: A₁ + ‥ + Aₙ ⊣ Θ₁ Θₘ ⊢ pₘ ↑ [Θₘ₋₁]Bₘ ⊣ Δ
-- -------------------------------------------------------------- -- --------------------------------------------------------------
-- Γ ⊢ injₖ xₖ. p₁ ‥ pₘ ↑ A₁ + ‥ + Aₙ ⊣ Δ -- Γ ⊢ injₖ xₖ. p₁ ‥ pₘ ↑ A₁ + ‥ + Aₙ ⊣ Δ
PInj name ps -> undefined PInj name ps -> do
-- injs <- maybeToRightM err1 =<< lookupDataType name_d traceT "t_patt :" t_patt
-- tinj <- liftEither . maybeToRight err2 $ lookup name injs (tdata, injs) <- maybeToRightM err1 =<< lookupDataType name_d
-- trace (show $ length foralls) pure () tinj <- liftEither . maybeToRight err2 $ lookup name injs
-- (tinj', tdata) <- substituteTVars foralls tinj tdata let foralls = getForallsData tdata
-- traceT "tinj'" tinj' (tinj', tdata) <- substituteTVars foralls tinj tdata
-- traceT "tdata" tdata let t = getTData $ getReturn tinj'
-- subtype (getTData $ getReturn tinj') tdata traceT "t :" t
-- t_inj'' <- applyEnv tinj' let super = getTData tdata
-- tdata' <- applyEnv tdata traceT "super" super
-- pure $ T.PInj (coerce name) [] subtype t super
t_inj'' <- applyEnv tinj'
tdata' <- applyEnv tdata
pure $ T.PInj (coerce name) []
-- §ps' <- zipWithM (\p t -> checkPattern p =<< applyEnv t) ps t_ps
where where
substituteTVars fas t1 t2 = case fas of substituteTVars fas t1 t2 = case fas of
[] -> pure (t1, t2) [] -> pure (t1, t2)
@ -595,10 +601,9 @@ checkPattern patt t_patt = (, t_patt) <$> case patt of
go fa (t1, t2) = let TAll tvar _ = fa dummy in do go fa (t1, t2) = let TAll tvar _ = fa dummy in do
tevar <- fresh tevar <- fresh
insertEnv (EnvTEVar tevar) insertEnv (EnvTEVar tevar)
traceT "tevar:" (TEVar tevar)
pure $ on (,) (substitute tvar tevar) t1 t2 pure $ on (,) (substitute tvar tevar) t1 t2
(foralls, tdata@(TData name_d _)) = partitionData t_patt TData name_d _ = getTData t_patt
err1 = unwords ["Unknown data type", show name_d] err1 = unwords ["Unknown data type", show name_d]
err2 = unwords ["No", show name, "constructor for data type", show name_d] err2 = unwords ["No", show name, "constructor for data type", show name_d]
@ -904,7 +909,7 @@ dummy = TLit "Int"
traceEnv s = do traceEnv s = do
env <- gets env env <- gets env
trace (s ++ " " ++ show env) pure () trace (s ++ " " ++ ppEnv env) pure ()
traceD s x = trace (s ++ " " ++ show x) pure () traceD s x = trace (s ++ " " ++ show x) pure ()