Safe Haskell | None |
---|---|
Language | Haskell2010 |
A class for unification
Synopsis
- class (Eq (UVarOf m # t), RTraversable t, ZipMatch t, HasTypeConstraints t, HasQuantifiedVar t, Monad m, MonadQuantify (TypeConstraintsOf t) (QVar t) m) => Unify m t where
- binding :: BindingDict (UVarOf m) m t
- unifyError :: (UnifyError t # UVarOf m) -> m a
- structureMismatch :: (forall c. Unify m c => (UVarOf m # c) -> (UVarOf m # c) -> m (UVarOf m # c)) -> (t # UVarOf m) -> (t # UVarOf m) -> m ()
- unifyRecursive :: Proxy m -> Proxy t -> Dict (HNodesConstraint t (Unify m))
- type family UVarOf (m :: Type -> Type) :: HyperType
- class Unify m t => UnifyGen m t where
- scopeConstraints :: Proxy t -> m (TypeConstraintsOf t)
- unifyGenRecursive :: Proxy m -> Proxy t -> Dict (HNodesConstraint t (UnifyGen m))
- data BindingDict v m t = BindingDict {}
- applyBindings :: forall m t. Unify m t => (UVarOf m # t) -> m (Pure # t)
- semiPruneLookup :: Unify m t => (UVarOf m # t) -> m (UVarOf m # t, UTerm (UVarOf m) # t)
- occursError :: Unify m t => (UVarOf m # t) -> (UTermBody (UVarOf m) # t) -> m a
Documentation
class (Eq (UVarOf m # t), RTraversable t, ZipMatch t, HasTypeConstraints t, HasQuantifiedVar t, Monad m, MonadQuantify (TypeConstraintsOf t) (QVar t) m) => Unify m t where Source #
Unify m t
enables unify
to perform unification for t
in the Monad
m
.
The unifyRecursive
method represents the constraint that Unify m
applies to all recursive child nodes.
It replaces context for Unify
to avoid UndecidableSuperClasses
.
binding :: BindingDict (UVarOf m) m t Source #
The implementation for unification variables binding and lookup
unifyError :: (UnifyError t # UVarOf m) -> m a Source #
Handles a unification error.
If unifyError
is called then unification has failed.
A compiler implementation may present an error message based on the provided UnifyError
when this occurs.
default unifyError :: (MonadError (e # Pure) m, HSubset' e (UnifyError t)) => (UnifyError t # UVarOf m) -> m a Source #
structureMismatch :: (forall c. Unify m c => (UVarOf m # c) -> (UVarOf m # c) -> m (UVarOf m # c)) -> (t # UVarOf m) -> (t # UVarOf m) -> m () Source #
What to do when top-levels of terms being unified do not match.
Usually this will cause a unifyError
.
Some AST terms could be equivalent despite not matching structurally, like record field extentions with the fields ordered differently. Those would override the default implementation to handle the unification of mismatching structures.
unifyRecursive :: Proxy m -> Proxy t -> Dict (HNodesConstraint t (Unify m)) Source #
default unifyRecursive :: HNodesConstraint t (Unify m) => Proxy m -> Proxy t -> Dict (HNodesConstraint t (Unify m)) Source #
type family UVarOf (m :: Type -> Type) :: HyperType Source #
Unification variable type for a unification monad
class Unify m t => UnifyGen m t where Source #
A class for unification monads with scope levels
scopeConstraints :: Proxy t -> m (TypeConstraintsOf t) Source #
Get the current scope constraint
unifyGenRecursive :: Proxy m -> Proxy t -> Dict (HNodesConstraint t (UnifyGen m)) Source #
default unifyGenRecursive :: HNodesConstraint t (UnifyGen m) => Proxy m -> Proxy t -> Dict (HNodesConstraint t (UnifyGen m)) Source #
data BindingDict v m t Source #
BindingDict implements unification variables for a type in a unification monad.
It is parameterized on:
Has 2 implementations in hypertypes:
bindingDict
for pure state based unificationstBinding
forST
based unification
applyBindings :: forall m t. Unify m t => (UVarOf m # t) -> m (Pure # t) Source #
Resolve a term from a unification variable.
Note that this must be done after all unifications involving the term and its children are done, as it replaces unification state with cached resolved terms.