Copyright | (c) 2008--2009 Universiteit Utrecht |
---|---|
License | BSD3 |
Maintainer | generics@haskell.org |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe |
Language | Haskell98 |
The generic zipper.
Synopsis
- data Loc :: (* -> *) -> (* -> *) -> * -> *
- data family Ctx (f :: (* -> *) -> * -> *) :: * -> (* -> *) -> * -> *
- class HFunctor phi f => Zipper phi f where
- cmapA :: Applicative a => (forall ix. phi ix -> r ix -> a (r' ix)) -> phi ix -> Ctx f b r ix -> a (Ctx f b r' ix)
- fill :: phi b -> Ctx f b r ix -> r b -> f r ix
- first, last :: (forall b. phi b -> r b -> Ctx f b r ix -> a) -> f r ix -> Maybe a
- next, prev :: (forall b. phi b -> r b -> Ctx f b r ix -> a) -> phi b -> Ctx f b r ix -> r b -> Maybe a
- enter :: (Fam phi, Zipper phi (PF phi)) => phi ix -> ix -> Loc phi I0 ix
- down :: Loc phi I0 ix -> Maybe (Loc phi I0 ix)
- down' :: Loc phi I0 ix -> Maybe (Loc phi I0 ix)
- up :: Loc phi I0 ix -> Maybe (Loc phi I0 ix)
- right :: Loc phi r ix -> Maybe (Loc phi r ix)
- left :: Loc phi r ix -> Maybe (Loc phi r ix)
- dfnext :: Loc phi I0 ix -> Maybe (Loc phi I0 ix)
- dfprev :: Loc phi I0 ix -> Maybe (Loc phi I0 ix)
- leave :: Loc phi I0 ix -> ix
- on :: (forall xi. phi xi -> r xi -> a) -> Loc phi r ix -> a
- update :: (forall xi. phi xi -> xi -> xi) -> Loc phi I0 ix -> Loc phi I0 ix
- updateF :: Functor f => (forall xi. phi xi -> xi -> f xi) -> Loc phi I0 ix -> f (Loc phi I0 ix)
- foldZipper :: (forall xi. phi xi -> xi -> r xi) -> Algebra phi r -> Loc phi I0 ix -> r ix
Locations
data Loc :: (* -> *) -> (* -> *) -> * -> * Source #
Abstract type of locations. A location contains the current focus and its context. A location is parameterized over the family of datatypes and over the type of the complete value.
Instances
HFunctor phi (Loc phi) Source # | |
Defined in Generics.MultiRec.Zipper hmapA :: Applicative a => (forall ix1. phi ix1 -> r ix1 -> a (r' ix1)) -> phi ix -> Loc phi r ix -> a (Loc phi r' ix) # |
Context frames
data family Ctx (f :: (* -> *) -> * -> *) :: * -> (* -> *) -> * -> * Source #
Abstract type of context frames. Not required for the high-level navigation functions.
Instances
Zipper phi f => HFunctor phi (Ctx f b) Source # | |
Defined in Generics.MultiRec.Zipper hmapA :: Applicative a => (forall ix1. phi ix1 -> r ix1 -> a (r' ix1)) -> phi ix -> Ctx f b r ix -> a (Ctx f b r' ix) # | |
data Ctx U b r ix Source # | |
Defined in Generics.MultiRec.Zipper | |
data Ctx (I xi) b r ix Source # | |
Defined in Generics.MultiRec.Zipper | |
data Ctx (K a) b r ix Source # | |
Defined in Generics.MultiRec.Zipper | |
data Ctx (f :+: g) b r ix Source # | |
data Ctx (f :*: g) b r ix Source # | |
data Ctx (f :>: xi) b r ix Source # | |
data Ctx ([] :.: g) b r ix Source # | |
Defined in Generics.MultiRec.Zipper | |
data Ctx (Maybe :.: g) b r ix Source # | |
data Ctx (C c f) b r ix Source # | |
Defined in Generics.MultiRec.Zipper |
Generic zipper class
class HFunctor phi f => Zipper phi f where Source #
It is in general not necessary to use the generic navigation
functions directly. The functions listed in the `Interface'
section
below are more user-friendly.
cmapA :: Applicative a => (forall ix. phi ix -> r ix -> a (r' ix)) -> phi ix -> Ctx f b r ix -> a (Ctx f b r' ix) Source #
fill :: phi b -> Ctx f b r ix -> r b -> f r ix Source #
first :: (forall b. phi b -> r b -> Ctx f b r ix -> a) -> f r ix -> Maybe a Source #
last :: (forall b. phi b -> r b -> Ctx f b r ix -> a) -> f r ix -> Maybe a Source #
next :: (forall b. phi b -> r b -> Ctx f b r ix -> a) -> phi b -> Ctx f b r ix -> r b -> Maybe a Source #
prev :: (forall b. phi b -> r b -> Ctx f b r ix -> a) -> phi b -> Ctx f b r ix -> r b -> Maybe a Source #
Instances
Zipper phi U Source # | |
Defined in Generics.MultiRec.Zipper cmapA :: Applicative a => (forall ix. phi ix -> r ix -> a (r' ix)) -> phi ix -> Ctx U b r ix -> a (Ctx U b r' ix) Source # fill :: phi b -> Ctx U b r ix -> r b -> U r ix Source # first :: (forall b. phi b -> r b -> Ctx U b r ix -> a) -> U r ix -> Maybe a Source # last :: (forall b. phi b -> r b -> Ctx U b r ix -> a) -> U r ix -> Maybe a Source # next :: (forall b. phi b -> r b -> Ctx U b r ix -> a) -> phi b -> Ctx U b r ix -> r b -> Maybe a Source # prev :: (forall b. phi b -> r b -> Ctx U b r ix -> a) -> phi b -> Ctx U b r ix -> r b -> Maybe a Source # | |
Zipper phi (K a) Source # | |
Defined in Generics.MultiRec.Zipper cmapA :: Applicative a0 => (forall ix. phi ix -> r ix -> a0 (r' ix)) -> phi ix -> Ctx (K a) b r ix -> a0 (Ctx (K a) b r' ix) Source # fill :: phi b -> Ctx (K a) b r ix -> r b -> K a r ix Source # first :: (forall b. phi b -> r b -> Ctx (K a) b r ix -> a0) -> K a r ix -> Maybe a0 Source # last :: (forall b. phi b -> r b -> Ctx (K a) b r ix -> a0) -> K a r ix -> Maybe a0 Source # next :: (forall b. phi b -> r b -> Ctx (K a) b r ix -> a0) -> phi b -> Ctx (K a) b r ix -> r b -> Maybe a0 Source # prev :: (forall b. phi b -> r b -> Ctx (K a) b r ix -> a0) -> phi b -> Ctx (K a) b r ix -> r b -> Maybe a0 Source # | |
El phi xi => Zipper phi (I xi) Source # | |
Defined in Generics.MultiRec.Zipper cmapA :: Applicative a => (forall ix. phi ix -> r ix -> a (r' ix)) -> phi ix -> Ctx (I xi) b r ix -> a (Ctx (I xi) b r' ix) Source # fill :: phi b -> Ctx (I xi) b r ix -> r b -> I xi r ix Source # first :: (forall b. phi b -> r b -> Ctx (I xi) b r ix -> a) -> I xi r ix -> Maybe a Source # last :: (forall b. phi b -> r b -> Ctx (I xi) b r ix -> a) -> I xi r ix -> Maybe a Source # next :: (forall b. phi b -> r b -> Ctx (I xi) b r ix -> a) -> phi b -> Ctx (I xi) b r ix -> r b -> Maybe a Source # prev :: (forall b. phi b -> r b -> Ctx (I xi) b r ix -> a) -> phi b -> Ctx (I xi) b r ix -> r b -> Maybe a Source # | |
(Constructor c, Zipper phi f) => Zipper phi (C c f) Source # | |
Defined in Generics.MultiRec.Zipper cmapA :: Applicative a => (forall ix. phi ix -> r ix -> a (r' ix)) -> phi ix -> Ctx (C c f) b r ix -> a (Ctx (C c f) b r' ix) Source # fill :: phi b -> Ctx (C c f) b r ix -> r b -> C c f r ix Source # first :: (forall b. phi b -> r b -> Ctx (C c f) b r ix -> a) -> C c f r ix -> Maybe a Source # last :: (forall b. phi b -> r b -> Ctx (C c f) b r ix -> a) -> C c f r ix -> Maybe a Source # next :: (forall b. phi b -> r b -> Ctx (C c f) b r ix -> a) -> phi b -> Ctx (C c f) b r ix -> r b -> Maybe a Source # prev :: (forall b. phi b -> r b -> Ctx (C c f) b r ix -> a) -> phi b -> Ctx (C c f) b r ix -> r b -> Maybe a Source # | |
Zipper phi f => Zipper phi (f :>: xi) Source # | |
Defined in Generics.MultiRec.Zipper cmapA :: Applicative a => (forall ix. phi ix -> r ix -> a (r' ix)) -> phi ix -> Ctx (f :>: xi) b r ix -> a (Ctx (f :>: xi) b r' ix) Source # fill :: phi b -> Ctx (f :>: xi) b r ix -> r b -> (f :>: xi) r ix Source # first :: (forall b. phi b -> r b -> Ctx (f :>: xi) b r ix -> a) -> (f :>: xi) r ix -> Maybe a Source # last :: (forall b. phi b -> r b -> Ctx (f :>: xi) b r ix -> a) -> (f :>: xi) r ix -> Maybe a Source # next :: (forall b. phi b -> r b -> Ctx (f :>: xi) b r ix -> a) -> phi b -> Ctx (f :>: xi) b r ix -> r b -> Maybe a Source # prev :: (forall b. phi b -> r b -> Ctx (f :>: xi) b r ix -> a) -> phi b -> Ctx (f :>: xi) b r ix -> r b -> Maybe a Source # | |
Zipper phi g => Zipper phi (Maybe :.: g) Source # | |
Defined in Generics.MultiRec.Zipper cmapA :: Applicative a => (forall ix. phi ix -> r ix -> a (r' ix)) -> phi ix -> Ctx (Maybe :.: g) b r ix -> a (Ctx (Maybe :.: g) b r' ix) Source # fill :: phi b -> Ctx (Maybe :.: g) b r ix -> r b -> (Maybe :.: g) r ix Source # first :: (forall b. phi b -> r b -> Ctx (Maybe :.: g) b r ix -> a) -> (Maybe :.: g) r ix -> Maybe a Source # last :: (forall b. phi b -> r b -> Ctx (Maybe :.: g) b r ix -> a) -> (Maybe :.: g) r ix -> Maybe a Source # next :: (forall b. phi b -> r b -> Ctx (Maybe :.: g) b r ix -> a) -> phi b -> Ctx (Maybe :.: g) b r ix -> r b -> Maybe a Source # prev :: (forall b. phi b -> r b -> Ctx (Maybe :.: g) b r ix -> a) -> phi b -> Ctx (Maybe :.: g) b r ix -> r b -> Maybe a Source # | |
Zipper phi g => Zipper phi ([] :.: g) Source # | |
Defined in Generics.MultiRec.Zipper cmapA :: Applicative a => (forall ix. phi ix -> r ix -> a (r' ix)) -> phi ix -> Ctx ([] :.: g) b r ix -> a (Ctx ([] :.: g) b r' ix) Source # fill :: phi b -> Ctx ([] :.: g) b r ix -> r b -> ([] :.: g) r ix Source # first :: (forall b. phi b -> r b -> Ctx ([] :.: g) b r ix -> a) -> ([] :.: g) r ix -> Maybe a Source # last :: (forall b. phi b -> r b -> Ctx ([] :.: g) b r ix -> a) -> ([] :.: g) r ix -> Maybe a Source # next :: (forall b. phi b -> r b -> Ctx ([] :.: g) b r ix -> a) -> phi b -> Ctx ([] :.: g) b r ix -> r b -> Maybe a Source # prev :: (forall b. phi b -> r b -> Ctx ([] :.: g) b r ix -> a) -> phi b -> Ctx ([] :.: g) b r ix -> r b -> Maybe a Source # | |
(Zipper phi f, Zipper phi g) => Zipper phi (f :*: g) Source # | |
Defined in Generics.MultiRec.Zipper cmapA :: Applicative a => (forall ix. phi ix -> r ix -> a (r' ix)) -> phi ix -> Ctx (f :*: g) b r ix -> a (Ctx (f :*: g) b r' ix) Source # fill :: phi b -> Ctx (f :*: g) b r ix -> r b -> (f :*: g) r ix Source # first :: (forall b. phi b -> r b -> Ctx (f :*: g) b r ix -> a) -> (f :*: g) r ix -> Maybe a Source # last :: (forall b. phi b -> r b -> Ctx (f :*: g) b r ix -> a) -> (f :*: g) r ix -> Maybe a Source # next :: (forall b. phi b -> r b -> Ctx (f :*: g) b r ix -> a) -> phi b -> Ctx (f :*: g) b r ix -> r b -> Maybe a Source # prev :: (forall b. phi b -> r b -> Ctx (f :*: g) b r ix -> a) -> phi b -> Ctx (f :*: g) b r ix -> r b -> Maybe a Source # | |
(Zipper phi f, Zipper phi g) => Zipper phi (f :+: g) Source # | |
Defined in Generics.MultiRec.Zipper cmapA :: Applicative a => (forall ix. phi ix -> r ix -> a (r' ix)) -> phi ix -> Ctx (f :+: g) b r ix -> a (Ctx (f :+: g) b r' ix) Source # fill :: phi b -> Ctx (f :+: g) b r ix -> r b -> (f :+: g) r ix Source # first :: (forall b. phi b -> r b -> Ctx (f :+: g) b r ix -> a) -> (f :+: g) r ix -> Maybe a Source # last :: (forall b. phi b -> r b -> Ctx (f :+: g) b r ix -> a) -> (f :+: g) r ix -> Maybe a Source # next :: (forall b. phi b -> r b -> Ctx (f :+: g) b r ix -> a) -> phi b -> Ctx (f :+: g) b r ix -> r b -> Maybe a Source # prev :: (forall b. phi b -> r b -> Ctx (f :+: g) b r ix -> a) -> phi b -> Ctx (f :+: g) b r ix -> r b -> Maybe a Source # |
Interface
enter :: (Fam phi, Zipper phi (PF phi)) => phi ix -> ix -> Loc phi I0 ix Source #
Start navigating a datastructure. Returns a location that focuses the entire value and has an empty context.
down :: Loc phi I0 ix -> Maybe (Loc phi I0 ix) Source #
Move down to the leftmost child. Returns Nothing
if the
current focus is a leaf.
down' :: Loc phi I0 ix -> Maybe (Loc phi I0 ix) Source #
Move down to the rightmost child. Returns Nothing
if the
current focus is a leaf.
up :: Loc phi I0 ix -> Maybe (Loc phi I0 ix) Source #
Move up to the parent. Returns Nothing
if the current
focus is the root.
right :: Loc phi r ix -> Maybe (Loc phi r ix) Source #
Move to the right sibling. Returns Nothing
if the current
focus is the rightmost sibling.
left :: Loc phi r ix -> Maybe (Loc phi r ix) Source #
Move to the left sibling. Returns Nothing
if the current
focus is the leftmost sibling.
dfnext :: Loc phi I0 ix -> Maybe (Loc phi I0 ix) Source #
Move through all positions in depth-first left-to-right order.
dfprev :: Loc phi I0 ix -> Maybe (Loc phi I0 ix) Source #
Move through all positions in depth-first right-to-left order.
on :: (forall xi. phi xi -> r xi -> a) -> Loc phi r ix -> a Source #
Operate on the current focus. This function can be used to extract the current point of focus.
update :: (forall xi. phi xi -> xi -> xi) -> Loc phi I0 ix -> Loc phi I0 ix Source #
Update the current focus without changing its type.
updateF :: Functor f => (forall xi. phi xi -> xi -> f xi) -> Loc phi I0 ix -> f (Loc phi I0 ix) Source #
Update the current focus, embedded in a functor.
foldZipper :: (forall xi. phi xi -> xi -> r xi) -> Algebra phi r -> Loc phi I0 ix -> r ix Source #
Most general eliminator. Both on
and update
can be defined
in terms of foldZipper
.