covenant
Copyright(C) MLabs 2025
LicenseApache 2.0
Maintainerkoz@mlabs.city, sean@mlabs.city
Safe HaskellNone
LanguageHaskell2010

Covenant.Zipper

Description

A read-only zipper for the Covenant ASG, based on an action monad.

Since: 1.3.0

Synopsis

Types

data ZipperAction Source #

A requested movement from the zipper. To build these, use dedicated smart constructors in this module. You can 'chain together' ZipperAction using the Semigroup instance.

Since: 1.3.0

data Tape a b Source #

A 'list with a focus', which may be of a different type to the rest. The first field is 'backwards', in that its first element is actually the furthest from the focus. Thus, if we have Tape [3, 2, 1] "foo" [4, 5], the 'list' actually looks like this:

[1, 2, 3, "foo", 4, 5]

but not like this:

[3, 2, 1, "foo", 4, 5]

Since: 1.3.0

Constructors

Tape [a] b [a] 

Instances

Instances details
Functor (Tape a) Source #

Since: 1.3.0

Instance details

Defined in Covenant.Zipper

Methods

fmap :: (a0 -> b) -> Tape a a0 -> Tape a b #

(<$) :: a0 -> Tape a b -> Tape a a0 #

data ZipperState where Source #

The current state of the zipper, including whether it's in a broken state or not, and if not in a broken state, the current position and the path taken to get here.

Since: 1.3.0

Bundled Patterns

pattern WorkingZipper :: [Tape Ref Id] -> Tape Ref (Either Arg (Id, ASGNode)) -> ZipperState

Matches on a working zipper, giving access to a stack of Tapes representing the path taken to get here (tracking sibling positions) and the current position, with the focus at either an Arg or an ASGNode.

Parent positions use Id for the focus, as Args cannot have descendants.

Since: 1.3.0

pattern BrokenZipper :: ZipperState

Matches on a zipper in a broken state.

Since: 1.3.0

data ASGZipper a Source #

A 'zipper command monad', designed to traverse an ASG. Based on an action monad.

To perform zipper moves, use send together with a ZipperAction. If you want to find out something about where we're standing, use request, together with pattern matching on ZipperState.

Since: 1.3.0

Instances

Instances details
Applicative ASGZipper Source #

Since: 1.3.0

Instance details

Defined in Covenant.Zipper

Methods

pure :: a -> ASGZipper a #

(<*>) :: ASGZipper (a -> b) -> ASGZipper a -> ASGZipper b #

liftA2 :: (a -> b -> c) -> ASGZipper a -> ASGZipper b -> ASGZipper c #

(*>) :: ASGZipper a -> ASGZipper b -> ASGZipper b #

(<*) :: ASGZipper a -> ASGZipper b -> ASGZipper a #

Functor ASGZipper Source #

Since: 1.3.0

Instance details

Defined in Covenant.Zipper

Methods

fmap :: (a -> b) -> ASGZipper a -> ASGZipper b #

(<$) :: a -> ASGZipper b -> ASGZipper a #

Monad ASGZipper Source #

Since: 1.3.0

Instance details

Defined in Covenant.Zipper

Methods

(>>=) :: ASGZipper a -> (a -> ASGZipper b) -> ASGZipper b #

(>>) :: ASGZipper a -> ASGZipper b -> ASGZipper b #

return :: a -> ASGZipper a #

MonadUpdate ZipperAction ASGZipper Source #

Since: 1.3.0

Instance details

Defined in Covenant.Zipper

Functions

Actions

moveUp :: ZipperAction Source #

Move towards the source of the ASG, 'back up' along the path taken to reach the current position. Will put the zipper in a broken state if used at the source node.

Since: 1.3.0

moveDown :: ZipperAction Source #

Move to the leftmost child of the current position. Will put the zipper in a broken state if used at a sink node.

Since: 1.3.0

moveLeft :: ZipperAction Source #

Move to the sibling immediately to the left of the current position. Will put the zipper in a broken state if used at a leftmost sibling.

Since: 1.3.0

moveRight :: ZipperAction Source #

Move to the sibling immediately to the right of the current position. Will put the zipper in a broken state if used at a rightmost sibling.

Since: 1.3.0

resetZipper :: ZipperAction Source #

If the zipper is currently in a broken state, reset it to the last position it was at before breaking. Otherwise, this does nothing.

Since: 1.3.0

Elimination

runASGZipper :: ASG -> ASGZipper a -> a Source #

Perform the stated actions to traverse over the ASG given by the argument.

Since: 1.3.0