Commit c56da5ff authored by Jan Rasmus Tikovsky 's avatar Jan Rasmus Tikovsky

Some refactoring + added new tests

parent 8645929f
...@@ -45,11 +45,11 @@ instance SubstType Type where ...@@ -45,11 +45,11 @@ instance SubstType Type where
subst sigma (TypeArrow ty1 ty2) = subst sigma (TypeArrow ty1 ty2) =
TypeArrow (subst sigma ty1) (subst sigma ty2) TypeArrow (subst sigma ty1) (subst sigma ty2)
subst _ ts@(TypeSkolem _) = ts subst _ ts@(TypeSkolem _) = ts
subst sigma (TypeRecord fs rv) subst sigma (TypeRecord fs rv) = case rv of
| isJust rv = case substVar sigma (fromJust rv) of Nothing -> TypeRecord fs' Nothing
TypeVariable tv -> TypeRecord fs' (Just tv) Just r' -> case substVar sigma r' of
ty -> ty TypeVariable tv -> TypeRecord fs' (Just tv)
| otherwise = TypeRecord fs' Nothing ty -> ty
where fs' = map (\ (l,ty) -> (l, subst sigma ty)) fs where fs' = map (\ (l,ty) -> (l, subst sigma ty)) fs
instance SubstType TypeScheme where instance SubstType TypeScheme where
...@@ -80,19 +80,17 @@ instance SubstType a => SubstType (TopEnv a) where ...@@ -80,19 +80,17 @@ instance SubstType a => SubstType (TopEnv a) where
expandAliasType :: [Type] -> Type -> Type expandAliasType :: [Type] -> Type -> Type
expandAliasType tys (TypeConstructor tc tys') = expandAliasType tys (TypeConstructor tc tys') =
TypeConstructor tc (map (expandAliasType tys) tys') TypeConstructor tc (map (expandAliasType tys) tys')
expandAliasType tys (TypeVariable n) expandAliasType tys (TypeVariable n)
| n >= 0 = tys !! n | n >= 0 = tys !! n
| otherwise = TypeVariable n | otherwise = TypeVariable n
expandAliasType _ (TypeConstrained tys n) = TypeConstrained tys n expandAliasType _ (TypeConstrained tys n) = TypeConstrained tys n
expandAliasType tys (TypeArrow ty1 ty2) = expandAliasType tys (TypeArrow ty1 ty2) =
TypeArrow (expandAliasType tys ty1) (expandAliasType tys ty2) TypeArrow (expandAliasType tys ty1) (expandAliasType tys ty2)
expandAliasType _ tsk@(TypeSkolem _) = tsk expandAliasType _ tsk@(TypeSkolem _) = tsk
expandAliasType tys (TypeRecord fs rv) expandAliasType tys (TypeRecord fs rv) = case rv of
| isJust rv = Nothing -> TypeRecord fs' Nothing
let (TypeVariable tv) = expandAliasType tys $ TypeVariable $ fromJust rv Just r' -> let (TypeVariable tv) = expandAliasType tys $ TypeVariable r'
in TypeRecord fs' (Just tv) in TypeRecord fs' (Just tv)
| otherwise =
TypeRecord fs' Nothing
where fs' = map (\ (l, ty) -> (l, expandAliasType tys ty)) fs where fs' = map (\ (l, ty) -> (l, expandAliasType tys ty)) fs
normalize :: Type -> Type normalize :: Type -> Type
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
- let expressions, and - let expressions, and
- case expressions. - case expressions.
* Applications 'N:x' in patterns and expressions, where 'N' is a * Applications 'N x' in patterns and expressions, where 'N' is a
newtype constructor, are replaced by a 'x'. Note that neither the newtype constructor, are replaced by a 'x'. Note that neither the
newtype declaration itself nor partial applications of newtype newtype declaration itself nor partial applications of newtype
constructors are changed (It were possible to replace partial constructors are changed (It were possible to replace partial
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
However, our solution yields a more accurate output when the result However, our solution yields a more accurate output when the result
of a computation includes partial applications.). of a computation includes partial applications.).
* Function patterns are replaced by variables and are integrated * Functional patterns are replaced by variables and are integrated
in a guarded right hand side using the (=:<=) operator in a guarded right hand side using the (=:<=) operator
* Records, which currently must be declared using the keyword * Records, which currently must be declared using the keyword
......
-- infixr 9 <$>
f <$> x = f x
\ No newline at end of file
s :: String
s = "hallo" :: String
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