diff --git a/src/Data/Abstract/Type.hs b/src/Data/Abstract/Type.hs index 2977e3893..ef492050d 100644 --- a/src/Data/Abstract/Type.hs +++ b/src/Data/Abstract/Type.hs @@ -14,7 +14,7 @@ data Type | String -- ^ Primitive string type. | Unit -- ^ The unit type. | Type :-> Type -- ^ Binary function types. - | TVar TName -- ^ A type variable. + | Var TName -- ^ A type variable. | Product [Type] -- ^ N-ary products. deriving (Eq, Ord, Show) @@ -26,8 +26,9 @@ unify :: MonadFail m => Type -> Type -> m Type unify Int Int = pure Int unify Bool Bool = pure Bool unify (a1 :-> b1) (a2 :-> b2) = (:->) <$> unify a1 a2 <*> unify b1 b2 -unify (TVar _) b = pure b -unify a (TVar _) = pure a +-- FIXME: this should be constructing a substitution. +unify (Var _) b = pure b +unify a (Var _) = pure a -- FIXME: this can succeed incorrectly for lists of inequal length. unify (Product as) (Product bs) = Product <$> for (zip as bs) (uncurry unify) unify t1 t2 = fail ("cannot unify " ++ show t1 ++ " with " ++ show t2) diff --git a/src/Data/Syntax/Declaration.hs b/src/Data/Syntax/Declaration.hs index 26dfaec3b..6d904ae76 100644 --- a/src/Data/Syntax/Declaration.hs +++ b/src/Data/Syntax/Declaration.hs @@ -66,7 +66,7 @@ instance ( Alternative m let params = toList (foldMap freeVariables functionParameters) tvars <- for params $ \name -> do a <- alloc name - tvar <- TVar <$> fresh + tvar <- Var <$> fresh assign a tvar pure (name, a, tvar) diff --git a/src/Data/Syntax/Expression.hs b/src/Data/Syntax/Expression.hs index fdd5a8bb5..9efe1a980 100644 --- a/src/Data/Syntax/Expression.hs +++ b/src/Data/Syntax/Expression.hs @@ -60,7 +60,7 @@ instance ( MonadFail m opTy <- recur pure callFunction tvar <- fresh inTys <- traverse (recur pure) callParams - _ :-> outTy <- opTy `unify` (Type.Product inTys :-> TVar tvar) + _ :-> outTy <- opTy `unify` (Type.Product inTys :-> Var tvar) yield outTy