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

Some refactoring + added new tests

parent 8645929f
......@@ -45,11 +45,11 @@ instance SubstType Type where
subst sigma (TypeArrow ty1 ty2) =
TypeArrow (subst sigma ty1) (subst sigma ty2)
subst _ ts@(TypeSkolem _) = ts
subst sigma (TypeRecord fs rv)
| isJust rv = case substVar sigma (fromJust rv) of
TypeVariable tv -> TypeRecord fs' (Just tv)
ty -> ty
| otherwise = TypeRecord fs' Nothing
subst sigma (TypeRecord fs rv) = case rv of
Nothing -> TypeRecord fs' Nothing
Just r' -> case substVar sigma r' of
TypeVariable tv -> TypeRecord fs' (Just tv)
ty -> ty
where fs' = map (\ (l,ty) -> (l, subst sigma ty)) fs
instance SubstType TypeScheme where
......@@ -80,19 +80,17 @@ instance SubstType a => SubstType (TopEnv a) where
expandAliasType :: [Type] -> Type -> Type
expandAliasType tys (TypeConstructor tc tys') =
TypeConstructor tc (map (expandAliasType tys) tys')
expandAliasType tys (TypeVariable n)
expandAliasType tys (TypeVariable n)
| n >= 0 = tys !! n
| otherwise = TypeVariable n
expandAliasType _ (TypeConstrained tys n) = TypeConstrained tys n
expandAliasType tys (TypeArrow ty1 ty2) =
TypeArrow (expandAliasType tys ty1) (expandAliasType tys ty2)
expandAliasType _ tsk@(TypeSkolem _) = tsk
expandAliasType tys (TypeRecord fs rv)
| isJust rv =
let (TypeVariable tv) = expandAliasType tys $ TypeVariable $ fromJust rv
in TypeRecord fs' (Just tv)
| otherwise =
TypeRecord fs' Nothing
expandAliasType tys (TypeRecord fs rv) = case rv of
Nothing -> TypeRecord fs' Nothing
Just r' -> let (TypeVariable tv) = expandAliasType tys $ TypeVariable r'
in TypeRecord fs' (Just tv)
where fs' = map (\ (l, ty) -> (l, expandAliasType tys ty)) fs
normalize :: Type -> Type
......
......@@ -36,7 +36,7 @@
- let expressions, and
- 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 declaration itself nor partial applications of newtype
constructors are changed (It were possible to replace partial
......@@ -44,7 +44,7 @@
However, our solution yields a more accurate output when the result
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
* 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