Changed data type check, removed dead code
This commit is contained in:
parent
2f62c017ec
commit
322286d898
1 changed files with 22 additions and 25 deletions
|
|
@ -217,12 +217,14 @@ checkBind (Bind name args e) = do
|
||||||
|
|
||||||
checkData :: (MonadState Env m, Monad m, MonadError Error m) => Data -> m ()
|
checkData :: (MonadState Env m, Monad m, MonadError Error m) => Data -> m ()
|
||||||
checkData err@(Data typ injs) = do
|
checkData err@(Data typ injs) = do
|
||||||
(name, tvars) <- go (skipForalls typ)
|
(name, tvars) <- go [] typ
|
||||||
dataErr (mapM_ (\i -> checkInj i name tvars) injs) err
|
dataErr (mapM_ (\i -> checkInj i name tvars) injs) err
|
||||||
where
|
where
|
||||||
go = \case
|
go tvars = \case
|
||||||
|
TAll tvar t -> go (tvar : tvars) t
|
||||||
TData name typs
|
TData name typs
|
||||||
| Right tvars' <- mapM toTVar typs ->
|
| Right tvars' <- mapM toTVar typs
|
||||||
|
, all (`elem` tvars) tvars' ->
|
||||||
pure (name, tvars')
|
pure (name, tvars')
|
||||||
_ ->
|
_ ->
|
||||||
uncatchableErr $
|
uncatchableErr $
|
||||||
|
|
@ -619,6 +621,15 @@ inst = \case
|
||||||
TFun t1 t2 -> TFun <$> inst t1 <*> inst t2
|
TFun t1 t2 -> TFun <$> inst t1 <*> inst t2
|
||||||
rest -> return rest
|
rest -> return rest
|
||||||
|
|
||||||
|
-- Only one of 'freshen' and 'inst' should be needed but something doesn't work
|
||||||
|
-- when I remove either.
|
||||||
|
freshen :: Type -> Infer Type
|
||||||
|
freshen t = do
|
||||||
|
let frees = S.toList (free t)
|
||||||
|
xs <- mapM (const fresh) frees
|
||||||
|
let sub = M.fromList $ zip frees xs
|
||||||
|
return $ apply sub t
|
||||||
|
|
||||||
-- | Generate a new fresh variable
|
-- | Generate a new fresh variable
|
||||||
fresh :: Infer Type
|
fresh :: Infer Type
|
||||||
fresh = do
|
fresh = do
|
||||||
|
|
@ -631,6 +642,7 @@ fresh = do
|
||||||
(<<=) a b = case (a, b) of
|
(<<=) a b = case (a, b) of
|
||||||
(TVar _, _) -> True
|
(TVar _, _) -> True
|
||||||
(TFun a b, TFun c d) -> a <<= c && b <<= d
|
(TFun a b, TFun c d) -> a <<= c && b <<= d
|
||||||
|
-- TAll still scuffed implementation here
|
||||||
(TAll tvar1 t1, TAll tvar2 t2) -> ungo [tvar1, tvar2] t1 t2
|
(TAll tvar1 t1, TAll tvar2 t2) -> ungo [tvar1, tvar2] t1 t2
|
||||||
(TAll tvar t1, t2) -> ungo [tvar] t1 t2
|
(TAll tvar t1, t2) -> ungo [tvar] t1 t2
|
||||||
(t1, TAll tvar t2) -> ungo [tvar] t1 t2
|
(t1, TAll tvar t2) -> ungo [tvar] t1 t2
|
||||||
|
|
@ -651,27 +663,10 @@ fresh = do
|
||||||
go tvars t1 t2 = do
|
go tvars t1 t2 = do
|
||||||
fr <- fresh
|
fr <- fresh
|
||||||
let sub = M.fromList [(coerce x, fr) | (MkTVar x) <- tvars]
|
let sub = M.fromList [(coerce x, fr) | (MkTVar x) <- tvars]
|
||||||
return (apply sub t1 <<= apply sub t2)
|
let t1' = apply sub t1
|
||||||
|
let t2' = apply sub t2
|
||||||
skipForalls :: Type -> Type
|
traceShow t1' (traceShow t2' pure ())
|
||||||
skipForalls = \case
|
return (t1' <<= t2')
|
||||||
TAll _ t -> skipForalls t
|
|
||||||
t -> t
|
|
||||||
|
|
||||||
freshen :: Type -> Infer Type
|
|
||||||
freshen t = do
|
|
||||||
let frees = S.toList (free t)
|
|
||||||
xs <- mapM (const fresh) frees
|
|
||||||
let sub = M.fromList $ zip frees xs
|
|
||||||
return $ apply sub t
|
|
||||||
|
|
||||||
{-
|
|
||||||
|
|
||||||
a = TVar $ MkTVar "a"
|
|
||||||
single = TData "single" [a]
|
|
||||||
arr = a `TFun` single
|
|
||||||
|
|
||||||
-}
|
|
||||||
|
|
||||||
-- | A class for substitutions
|
-- | A class for substitutions
|
||||||
class SubstType t where
|
class SubstType t where
|
||||||
|
|
@ -711,7 +706,9 @@ instance SubstType Type where
|
||||||
Just _ -> apply sub t
|
Just _ -> apply sub t
|
||||||
TFun a b -> TFun (apply sub a) (apply sub b)
|
TFun a b -> TFun (apply sub a) (apply sub b)
|
||||||
TData name a -> TData name (apply sub a)
|
TData name a -> TData name (apply sub a)
|
||||||
TEVar (MkTEVar _) -> t
|
TEVar (MkTEVar a) -> case M.lookup (coerce a) sub of
|
||||||
|
Nothing -> TEVar (MkTEVar $ coerce a)
|
||||||
|
Just t -> t
|
||||||
|
|
||||||
instance FreeVars (Map T.Ident Type) where
|
instance FreeVars (Map T.Ident Type) where
|
||||||
free :: Map T.Ident Type -> Set T.Ident
|
free :: Map T.Ident Type -> Set T.Ident
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue