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.
21 import Control.Monad.State
26 type Substitution = TypeScheme -> TypeScheme
27 type VarS a = State Int a
36 substitute :: TypeScheme -> TypeVarName -> TypeScheme -> TypeScheme
37 substitute = undefined
39 unify :: TypeScheme -> TypeScheme -> Either String Substitution
40 unify (TScheme (Primitive a)) (TScheme (Primitive b)) | a == b = Right id
41 unify (TScheme (TypeVar a)) (TScheme (TypeVar b)) | a == b = Right id
42 unify a b = Left $ "cannot unify " ++ show a ++ " with " ++ show b
44 algW :: TypedTerm -> Either String TypeScheme
45 algW (TTerm (Var _) t) = Right t
46 --algW (TTerm (Lam x t) (TScheme p)) = do
47 -- let v = TScheme (TypeVar fresh)
48 -- np = substitute v x t
50 --algW (TTerm (App u v) t) = do
54 -- (TScheme (TypeFunction a b)) -> do
57 -- _ -> Left $ "cannot apply " ++ show tu ++ " to " ++ show tv