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:
parent
e011a71835
commit
f8096013f9
@ -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)
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user