documented possible bad functions

This commit is contained in:
sebastianselander 2023-03-06 16:41:59 +01:00
parent eef6fa7668
commit fce54e7899
2 changed files with 17 additions and 22 deletions

View file

@ -1,17 +1,8 @@
-- double : _Int -> _Int ; -- double : _Int -> _Int ;
-- double n = n + n; -- double n = n + n;
apply : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c ;
apply f x y = f x y ;
id : 'a -> 'a ; id : 'a -> 'a ;
id x = x ; id x = x ;
add : _Int -> _Int -> _Int ; main : ('a -> 'b -> 'c) ;
add x y = x + y ; main = id ;
main : _Int -> _Int -> _Int ;
main = apply (id add) ;
idadd : _Int -> _Int -> _Int ;
idadd = id add ;

View file

@ -45,6 +45,7 @@ typecheck = run . checkPrg
{- | Start by freshening the type variable of data types to avoid clash with {- | Start by freshening the type variable of data types to avoid clash with
other user defined polymorphic types other user defined polymorphic types
This might be wrong for type constructors that work over several variables
-} -}
freshenData :: Data -> Infer Data freshenData :: Data -> Infer Data
freshenData (Data (Constr name ts) constrs) = do freshenData (Data (Constr name ts) constrs) = do
@ -59,7 +60,10 @@ freshenData (Data (Constr name ts) constrs) = do
let new_ts = map (freshenType fr') ts let new_ts = map (freshenType fr') ts
let new_constrs = map (freshenConstr fr') constrs let new_constrs = map (freshenConstr fr') constrs
return $ Data (Constr name new_ts) new_constrs return $ Data (Constr name new_ts) new_constrs
where
{- | Freshen all polymorphic variables, regardless of name
| freshenType "d" (a -> b -> c) becomes (d -> d -> d)
-}
freshenType :: Ident -> Type -> Type freshenType :: Ident -> Type -> Type
freshenType iden = \case freshenType iden = \case
(TPol _) -> TPol iden (TPol _) -> TPol iden