documented possible bad functions
This commit is contained in:
parent
eef6fa7668
commit
fce54e7899
2 changed files with 17 additions and 22 deletions
|
|
@ -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 ;
|
|
||||||
|
|
|
||||||
|
|
@ -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,17 +60,20 @@ 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
|
|
||||||
freshenType :: Ident -> Type -> Type
|
{- | Freshen all polymorphic variables, regardless of name
|
||||||
freshenType iden = \case
|
| freshenType "d" (a -> b -> c) becomes (d -> d -> d)
|
||||||
|
-}
|
||||||
|
freshenType :: Ident -> Type -> Type
|
||||||
|
freshenType iden = \case
|
||||||
(TPol _) -> TPol iden
|
(TPol _) -> TPol iden
|
||||||
(TArr a b) -> TArr (freshenType iden a) (freshenType iden b)
|
(TArr a b) -> TArr (freshenType iden a) (freshenType iden b)
|
||||||
(TConstr (Constr a ts)) ->
|
(TConstr (Constr a ts)) ->
|
||||||
TConstr (Constr a (map (freshenType iden) ts))
|
TConstr (Constr a (map (freshenType iden) ts))
|
||||||
rest -> rest
|
rest -> rest
|
||||||
|
|
||||||
freshenConstr :: Ident -> Constructor -> Constructor
|
freshenConstr :: Ident -> Constructor -> Constructor
|
||||||
freshenConstr iden (Constructor name t) =
|
freshenConstr iden (Constructor name t) =
|
||||||
Constructor name (freshenType iden t)
|
Constructor name (freshenType iden t)
|
||||||
|
|
||||||
checkData :: Data -> Infer ()
|
checkData :: Data -> Infer ()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue