pez-0.0.4: A Potentially-Excellent Zipper library

Data.Typeable.Zipper

Contents

Synopsis

Basic Zipper functionality

data Zipper a b Source

Instances

Creating and closing Zippers

zipper :: a -> Zipper a aSource

close :: Zipper a b -> aSource

Moving around

class ZPath p whereSource

Types of the ZPath class act as references to paths down through a datatype. Currently lenses from fclabels and SavedPath types are instances

Methods

moveTo :: (Typeable b, Typeable c) => p b c -> Zipper a b -> Zipper a cSource

Move down the structure to the label specified. Return Nothing if the label is not valid for the focus's constructor:

Instances

ZPath :->

a fclabel lens for setting, getting, and modifying the zipper's focus:

ZPath SavedPath 

moveUp :: (Typeable c, Typeable b) => Int -> Zipper a c -> Maybe (Zipper a b)Source

Move up n levels as long as the type of the parent is what the programmer is expecting and we aren't already at the top. Otherwise return Nothing.

Querying

focus :: :-> (Zipper a1 a) aSource

viewf :: Zipper a b -> bSource

a view function for a Zipper's focus. Defined simply as: getL focus

atTop :: Zipper a b -> BoolSource

returns True if Zipper is at the top level of the data structure:

Advanced functionality

Saving positions in a Zipper

data SavedPath a b Source

stores the path used to return to the same location in a data structure as the one we just exited. You can also extract a lens from a SavedPath that points to that location:

save :: Zipper a b -> SavedPath a bSource

Return a SavedPath type encapsulating the current location in the Zipper. This lets you return to a location in your data type after closing the Zipper.

saveFromAbove :: (Typeable c, Typeable b) => Int -> Zipper a c -> Maybe (SavedPath b c)Source

return a SavedPath from n levels up to the current level

savedLens :: (Typeable a, Typeable b) => SavedPath a b -> a :-> bSource

Extract a composed lens that points to the location we SavedPath. This lets us modify, set or get a location that we visited with our Zipper after closing the Zipper.

moveUpSaving :: (Typeable c, Typeable b) => Int -> Zipper a c -> Maybe (Zipper a b, SavedPath b c)Source

Move up a level as long as the type of the parent is what the programmer is expecting and we aren't already at the top. Otherwise return Nothing.

Recalling positions:

restore :: (ZPath p, Typeable a, Typeable b) => p a b -> a -> Zipper a bSource

Return to a previously SavedPath location within a data-structure. Saving and restoring lets us for example: find some location within our structure using a Zipper, save the location, fmap over the entire structure, and then return to where we were:

Convenience operators, types, and exports

type Zipper1 a = Zipper a aSource

a simple type synonym for a Zipper where the type at the focus is the same as the type of the outer (unzippered) type. Cleans up type signatures for simple recursive types:

Operators

(.+) :: (ZPath p, Typeable b, Typeable c) => Zipper a b -> p b c -> Zipper a cSource

moveTo with arguments flipped. Operator plays on the idea of addition of levels onto the focus.

(.>) :: Zipper a b -> b -> Zipper a bSource

setL focus, with arguments flipped

(.-) :: (Typeable c, Typeable b) => Zipper a c -> Int -> Maybe (Zipper a b)Source

moveUp with arguments flipped. Operator syntax comes from the idea of moving up as subtraction.

(?+) :: (ZPath p, Typeable b, Typeable c) => Maybe (Zipper a b) -> p b c -> Maybe (Zipper a c)Source

(?>) :: Maybe (Zipper a b) -> b -> Maybe (Zipper a b)Source

(?-) :: (Typeable c, Typeable b) => Maybe (Zipper a c) -> Int -> Maybe (Zipper a b)Source

Export Typeable class and fclabels package