License | BSD-3-Clause |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Swarm.Effect.Unify.Naive
Description
unification. Uses a simple but expensive-to-maintain invariant on substitutions, and returns a substitution from unification which must then be composed with the substitution being tracked.
Not used in Swarm, and also unmaintained (e.g. Swarm.Effect.Unify.Fast now supports expanding type aliases + recursive types; this module does not). It's still here just for testing/comparison.
Synopsis
- class Substitutes n b a where
- (@@) :: (Ord n, Substitutes n a a) => Subst n a -> Subst n a -> Subst n a
- compose :: (Ord n, Substitutes n a a, Foldable t) => t (Subst n a) -> Subst n a
- newtype UnificationC (m :: Type -> Type) a = UnificationC {
- unUnificationC :: StateC (Subst IntVar UType) (StateC FreshVarCounter (ThrowC UnificationError m)) a
- newtype FreshVarCounter = FreshVarCounter {}
- runUnification :: forall (sig :: (Type -> Type) -> Type -> Type) m a. Algebra sig m => UnificationC m a -> m (Either UnificationError a)
- unify :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (Throw UnificationError) sig m => UType -> UType -> m (Subst IntVar UType)
- unifyF :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (Throw UnificationError) sig m => TypeF UType -> TypeF UType -> m (Subst IntVar UType)
Documentation
class Substitutes n b a where Source #
Class of things supporting substitution. Substitutes n b a
means
that we can apply a substitution of type Subst n b
to a
value of type a
, replacing all the free names of type n
inside the a
with values of type b
, resulting in a new value
of type a
.
(@@) :: (Ord n, Substitutes n a a) => Subst n a -> Subst n a -> Subst n a Source #
Compose two substitutions. Applying s1 @@ s2
is the same as
applying first s2
, then s1
; that is, semantically,
composition of substitutions corresponds exactly to function
composition when they are considered as functions on terms.
As one would expect, composition is associative and has idS
as
its identity.
compose :: (Ord n, Substitutes n a a, Foldable t) => t (Subst n a) -> Subst n a Source #
Compose a whole container of substitutions. For example,
compose [s1, s2, s3] = s1 @@ s2 @@ s3
.
newtype UnificationC (m :: Type -> Type) a Source #
Carrier type for unification: we maintain a current substitution, a counter for generating fresh unification variables, and can throw unification errors.
Constructors
UnificationC | |
Fields
|
Instances
newtype FreshVarCounter Source #
Counter for generating fresh unification variables.
Constructors
FreshVarCounter | |
Fields |
Instances
runUnification :: forall (sig :: (Type -> Type) -> Type -> Type) m a. Algebra sig m => UnificationC m a -> m (Either UnificationError a) Source #
Run a Unification
effect via the UnificationC
carrier.