Commit ede37194 authored by Kai-Oliver Prott's avatar Kai-Oliver Prott

Convert IL-Types to weak prenex form

parent 5852fd84
...@@ -11,12 +11,23 @@ ...@@ -11,12 +11,23 @@
TODO TODO
-} -}
module IL.Typing (Typeable(..)) where module IL.Typing (Typeable(..), prenexType) where
import Base.Messages (internalError) import Base.Messages (internalError)
import IL.Type import IL.Type
-- | Converts the given type into prenex form.
prenexType :: Type -> Type
prenexType (TypeConstructor tc tys) = TypeConstructor tc $ map prenexType tys
prenexType tv@(TypeVariable _) = tv
prenexType (TypeArrow ty1 ty2) = case prenexType ty2 of
TypeForall tvs ty2' -> TypeForall tvs $ TypeArrow (prenexType ty1) ty2'
ty2' -> TypeArrow (prenexType ty1) ty2'
prenexType (TypeForall tvs ty) = case prenexType ty of
TypeForall tvs' ty' -> TypeForall (tvs ++ tvs') ty'
ty' -> TypeForall tvs ty'
class Typeable a where class Typeable a where
typeOf :: a -> Type typeOf :: a -> Type
......
...@@ -213,7 +213,7 @@ trExternal (Var ty f) = do ...@@ -213,7 +213,7 @@ trExternal (Var ty f) = do
-- type constructors. -- type constructors.
transType :: TCEnv -> Type -> IL.Type transType :: TCEnv -> Type -> IL.Type
transType tcEnv ty' = transType' ty' [] transType tcEnv ty' = IL.prenexType $ transType' ty' []
where where
ks = transTVars tcEnv ty' ks = transTVars tcEnv ty'
transType' (TypeConstructor tc) = IL.TypeConstructor tc transType' (TypeConstructor tc) = IL.TypeConstructor tc
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment