Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Generic
implementations of Logical
methods.
As discussed in the documentation for the Logical
class, method
implementations are not particularly interesting and can be easily
automated. This module provides such automated implementations using
Generic
.
This module expects that you already have a logical representation for your
type, and there's already a Logic
type instance. The logical type must not
change the order of constructors as well as the order of fields in each
constructor, but the names do not matter. Additionally, each field in the
original type must be wrapped in a Term
in the logical representation.
For example, consider the following type definition:
data Tree a = Leaf a | Node (Tree a) (Tree a) deriving (Generic) data LogicTree a = LogicLeaf (Term a) | LogicNode (Term (Tree a)) (Term (Tree a)) deriving (Generic)
From there, using the generic implementations is trivial:
instance (Logical a) => Logical (Tree a) where type Logic (Tree a) = LogicTree a unify = genericUnify subst = genericSubst inject = genericInject extract = genericExtract
Synopsis
- genericUnify :: forall a. (Generic (Logic a), GLogical (Rep a) (Rep (Logic a))) => Logic a -> Logic a -> State -> Maybe State
- genericWalk :: forall a. (Generic (Logic a), GLogical (Rep a) (Rep (Logic a))) => State -> Logic a -> Logic a
- genericOccursCheck :: forall a b. (Generic (Logic a), GLogical (Rep a) (Rep (Logic a))) => VarId b -> Logic a -> State -> Bool
- genericInject :: (Generic a, Generic (Logic a), GLogical (Rep a) (Rep (Logic a))) => a -> Logic a
- genericExtract :: (Generic a, Generic (Logic a), GLogical (Rep a) (Rep (Logic a))) => Logic a -> Maybe a
- class GLogical f f'
Documentation
genericUnify :: forall a. (Generic (Logic a), GLogical (Rep a) (Rep (Logic a))) => Logic a -> Logic a -> State -> Maybe State Source #
The generic implementation of unify
.
genericWalk :: forall a. (Generic (Logic a), GLogical (Rep a) (Rep (Logic a))) => State -> Logic a -> Logic a Source #
The generic implementation of walk
.
genericOccursCheck :: forall a b. (Generic (Logic a), GLogical (Rep a) (Rep (Logic a))) => VarId b -> Logic a -> State -> Bool Source #
The generic implementation of walk
.
genericInject :: (Generic a, Generic (Logic a), GLogical (Rep a) (Rep (Logic a))) => a -> Logic a Source #
The generic implementation of inject
.
genericExtract :: (Generic a, Generic (Logic a), GLogical (Rep a) (Rep (Logic a))) => Logic a -> Maybe a Source #
The generic implementation of extract
.
gunify, gwalk, goccursCheck, ginject, gextract
Instances
GLogical (U1 :: Type -> Type) (U1 :: Type -> Type) Source # | |
GLogical (V1 :: Type -> Type) (V1 :: Type -> Type) Source # | |
(GLogical f f', GLogical g g') => GLogical (f :*: g) (f' :*: g') Source # | |
(GLogical f f', GLogical g g') => GLogical (f :+: g) (f' :+: g') Source # | |
Logical c => GLogical (K1 i c :: Type -> Type) (K1 i' (Term c) :: Type -> Type) Source # | |
Defined in Kanren.GenericLogical | |
GLogical f f' => GLogical (M1 i t f) (M1 i' t' f') Source # | |
Defined in Kanren.GenericLogical |