3 -- Copyright : Tomáš Musil 2014
6 -- Maintainer : tomik.musil@gmail.com
7 -- Stability : experimental
9 -- This is a toy implementation of λ-calculus with Hindley-Milner type system.
22 type Substitution = TypeScheme -> TypeScheme
27 substitute :: TypeScheme -> TypeVarName -> TypeScheme -> TypeScheme
28 substitute = undefined
30 unify :: TypeScheme -> TypeScheme -> Either String Substitution
31 unify (TScheme (Primitive a)) (TScheme (Primitive b)) | a == b = Right id
32 unify (TScheme (TypeVar a)) (TScheme (TypeVar b)) | a == b = Right id
33 unify a b = Left $ "cannot unify " ++ show a ++ " with " ++ show b
35 algW :: HMTerm -> Either String TypeScheme
36 algW (HMTerm (Var _) t) = Right t
37 algW (HMTerm (Lambda x t) (TScheme p)) = do
38 let v = TScheme (TypeVar fresh)
41 algW (HMTerm (App u v) t) = do
45 (TScheme (TypeFunction a b)) -> do
48 _ -> Left $ "cannot apply " ++ show tu ++ " to " ++ show tv