Portability | ghc |
---|---|

Stability | unstable |

Maintainer | Andy Gill <andygill@ku.edu> |

- The
`Translate`

combinators - The
`Rewrite`

combinators - The Prelude combinators
- Generic failure, over both
`Monad`

s and`Translate`

s.

This module contains various combinators that use `Translate`

and `Rewrite`

. The convension is that
`Translate`

based combinators end with `T`

, and `Rewrite`

based combinators end with `R`

. Of course,
because `Rewrite`

is a type synomim of `Translate`

, the `Rewrite`

functions also operate with on `Translate`

,
and the `Translate`

functions operate with `Rewrite`

.

- (<+) :: (Monoid dec, Monad m) => Translate m dec a b -> Translate m dec a b -> Translate m dec a b
- (>->) :: (Monoid dec, Monad m) => Translate m dec a b -> Translate m dec b c -> Translate m dec a c
- failT :: (Monad m, Monoid dec) => String -> Translate m dec a b
- readerT :: (Monoid dec, Monad m) => (a -> Translate m dec a b) -> Translate m dec a b
- readEnvT :: (Monad m, Monoid dec) => (dec -> Translate m dec a b) -> Translate m dec a b
- mapEnvT :: (Monoid dec, Monad m) => (dec -> dec) -> Translate m dec a r -> Translate m dec a r
- writeEnvT :: (Monad m, Monoid dec) => dec -> Rewrite m dec a
- pureT :: (Monad m, Monoid dec) => (a -> b) -> Translate m dec a b
- constT :: (Monad m, Monoid dec) => b -> Translate m dec a b
- concatT :: (Monad m, Monoid dec, Monoid r) => [Translate m dec a r] -> Translate m dec a r
- (.+) :: (Monoid dec, Monad m) => Rewrite m dec a -> Rewrite m dec a -> Rewrite m dec a
- (!->) :: (Monoid dec, Monad m) => Rewrite m dec a -> Rewrite m dec a -> Rewrite m dec a
- tryR :: (Monoid dec, Monad m) => Rewrite m dec a -> Rewrite m dec a
- changedR :: (Monoid dec, Monad m) => Rewrite m dec a -> Rewrite m dec a
- repeatR :: (Monoid dec, Monad m) => Rewrite m dec a -> Rewrite m dec a
- acceptR :: (Monoid dec, Monad m) => (a -> Bool) -> Rewrite m dec a
- idR :: (Monad m, Monoid dec) => Rewrite m dec exp
- failR :: (Monad m, Monoid dec) => String -> Rewrite m dec a
- tuple2R :: (Monoid dec, Monad m) => Rewrite m dec a -> Rewrite m dec b -> Rewrite m dec (a, b)
- listR :: (Monoid dec, Monad m) => Rewrite m dec a -> Rewrite m dec [a]
- maybeR :: (Monoid dec, Monad m) => Rewrite m dec a -> Rewrite m dec (Maybe a)
- tuple2U :: (Monoid dec, Monad m, Monoid r) => Translate m dec a r -> Translate m dec b r -> Translate m dec (a, b) r
- listU :: (Monoid dec, Monad m, Monoid r) => Translate m dec a r -> Translate m dec [a] r
- maybeU :: (Monoid dec, Monad m, Monoid r) => Translate m dec a r -> Translate m dec (Maybe a) r
- (?) :: Failable f => Bool -> f a -> f a
- class Failable f where

# The `Translate`

combinators

(<+) :: (Monoid dec, Monad m) => Translate m dec a b -> Translate m dec a b -> Translate m dec a bSource

like a catch, `<+`

does the first translate , and if it fails, then does the second translate.

(>->) :: (Monoid dec, Monad m) => Translate m dec a b -> Translate m dec b c -> Translate m dec a cSource

like a `;`

If the first translate succeeds, then do to the second translate after the first translate.

readerT :: (Monoid dec, Monad m) => (a -> Translate m dec a b) -> Translate m dec a bSource

look at the argument for the translation before choosing which translation to perform.

readEnvT :: (Monad m, Monoid dec) => (dec -> Translate m dec a b) -> Translate m dec a bSource

look at the `dec`

before choosing which translation to do.

mapEnvT :: (Monoid dec, Monad m) => (dec -> dec) -> Translate m dec a r -> Translate m dec a rSource

change the `dec`

's for a scoped translation.

writeEnvT :: (Monad m, Monoid dec) => dec -> Rewrite m dec aSource

add to the context `dec`

, which is propogated using a writer monad.

# The `Rewrite`

combinators

(.+) :: (Monoid dec, Monad m) => Rewrite m dec a -> Rewrite m dec a -> Rewrite m dec aSource

if the first rewrite is an identity, then do the second rewrite.

(!->) :: (Monoid dec, Monad m) => Rewrite m dec a -> Rewrite m dec a -> Rewrite m dec aSource

if the first rewrite was *not* an identity, then also do the second rewrite.

tryR :: (Monoid dec, Monad m) => Rewrite m dec a -> Rewrite m dec aSource

catch a failing `Rewrite`

, making it into an identity.

changedR :: (Monoid dec, Monad m) => Rewrite m dec a -> Rewrite m dec aSource

if this is an identity rewrite, make it fail. To succeed, something must have changed.

repeatR :: (Monoid dec, Monad m) => Rewrite m dec a -> Rewrite m dec aSource

repeat a rewrite until it fails, then return the result before the failure.

acceptR :: (Monoid dec, Monad m) => (a -> Bool) -> Rewrite m dec aSource

look at the argument to a rewrite, and choose to be either a failure of trivial success.

# The Prelude combinators

tuple2R :: (Monoid dec, Monad m) => Rewrite m dec a -> Rewrite m dec b -> Rewrite m dec (a, b)Source

tuple2U :: (Monoid dec, Monad m, Monoid r) => Translate m dec a r -> Translate m dec b r -> Translate m dec (a, b) rSource

maybeU :: (Monoid dec, Monad m, Monoid r) => Translate m dec a r -> Translate m dec (Maybe a) rSource