1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 06:11:49 +03:00

Rename TVar to Var.

This commit is contained in:
Rob Rix 2017-12-21 17:07:15 -05:00
parent e011a71835
commit f8096013f9
3 changed files with 6 additions and 5 deletions

View File

@ -14,7 +14,7 @@ data Type
| String -- ^ Primitive string type. | String -- ^ Primitive string type.
| Unit -- ^ The unit type. | Unit -- ^ The unit type.
| Type :-> Type -- ^ Binary function types. | Type :-> Type -- ^ Binary function types.
| TVar TName -- ^ A type variable. | Var TName -- ^ A type variable.
| Product [Type] -- ^ N-ary products. | Product [Type] -- ^ N-ary products.
deriving (Eq, Ord, Show) deriving (Eq, Ord, Show)
@ -26,8 +26,9 @@ unify :: MonadFail m => Type -> Type -> m Type
unify Int Int = pure Int unify Int Int = pure Int
unify Bool Bool = pure Bool unify Bool Bool = pure Bool
unify (a1 :-> b1) (a2 :-> b2) = (:->) <$> unify a1 a2 <*> unify b1 b2 unify (a1 :-> b1) (a2 :-> b2) = (:->) <$> unify a1 a2 <*> unify b1 b2
unify (TVar _) b = pure b -- FIXME: this should be constructing a substitution.
unify a (TVar _) = pure a unify (Var _) b = pure b
unify a (Var _) = pure a
-- FIXME: this can succeed incorrectly for lists of inequal length. -- FIXME: this can succeed incorrectly for lists of inequal length.
unify (Product as) (Product bs) = Product <$> for (zip as bs) (uncurry unify) unify (Product as) (Product bs) = Product <$> for (zip as bs) (uncurry unify)
unify t1 t2 = fail ("cannot unify " ++ show t1 ++ " with " ++ show t2) unify t1 t2 = fail ("cannot unify " ++ show t1 ++ " with " ++ show t2)

View File

@ -66,7 +66,7 @@ instance ( Alternative m
let params = toList (foldMap freeVariables functionParameters) let params = toList (foldMap freeVariables functionParameters)
tvars <- for params $ \name -> do tvars <- for params $ \name -> do
a <- alloc name a <- alloc name
tvar <- TVar <$> fresh tvar <- Var <$> fresh
assign a tvar assign a tvar
pure (name, a, tvar) pure (name, a, tvar)

View File

@ -60,7 +60,7 @@ instance ( MonadFail m
opTy <- recur pure callFunction opTy <- recur pure callFunction
tvar <- fresh tvar <- fresh
inTys <- traverse (recur pure) callParams inTys <- traverse (recur pure) callParams
_ :-> outTy <- opTy `unify` (Type.Product inTys :-> TVar tvar) _ :-> outTy <- opTy `unify` (Type.Product inTys :-> Var tvar)
yield outTy yield outTy