| Portability | ghc |
|---|---|
| Stability | beta |
| Maintainer | Neil Sculthorpe <neil@ittc.ku.edu> |
| Safe Haskell | Safe-Inferred |
Language.KURE.Translate
Description
This module defines the main KURE types: Translate, Rewrite and Lens.
Rewrite is just a special case of Translate, and so any function that operates on Translate is also
applicable to Rewrite.
This module also contains Translate instance declarations for the Monad and Arrow type-class families.
Given these instances, many of the desirable combinators over Translate and Rewrite are special cases
of existing monadic or arrow combinators.
Language.KURE.Combinators provides some additional combinators that aren't in the standard libraries.
- data Translate c m a b
- type Rewrite c m a = Translate c m a a
- apply :: Translate c m a b -> c -> a -> m b
- translate :: (c -> a -> m b) -> Translate c m a b
- rewrite :: (c -> a -> m a) -> Rewrite c m a
- contextfreeT :: (a -> m b) -> Translate c m a b
- contextonlyT :: (c -> m b) -> Translate c m a b
- constT :: m b -> Translate c m a b
- contextT :: Monad m => Translate c m a c
- exposeT :: Monad m => Translate c m a (c, a)
- mapT :: (Traversable t, Monad m) => Translate c m a b -> Translate c m (t a) (t b)
- sideEffectR :: Monad m => (c -> a -> m ()) -> Rewrite c m a
- data BiTranslate c m a b
- type BiRewrite c m a = BiTranslate c m a a
- bidirectional :: Translate c m a b -> Translate c m b a -> BiTranslate c m a b
- forewardT :: BiTranslate c m a b -> Translate c m a b
- backwardT :: BiTranslate c m a b -> Translate c m b a
- whicheverR :: MonadCatch m => BiRewrite c m a -> Rewrite c m a
- invert :: BiTranslate c m a b -> BiTranslate c m b a
- data Lens c m a b
- lens :: Translate c m a ((c, b), b -> m a) -> Lens c m a b
- lensT :: Lens c m a b -> Translate c m a ((c, b), b -> m a)
- focusR :: Monad m => Lens c m a b -> Rewrite c m b -> Rewrite c m a
- focusT :: Monad m => Lens c m a b -> Translate c m b d -> Translate c m a d
- testLensT :: MonadCatch m => Lens c m a b -> Translate c m a Bool
- bidirectionalL :: Monad m => BiTranslate c m a b -> Lens c m a b
- pureL :: Monad m => (a -> b) -> (b -> a) -> Lens c m a b
Translations
An abstract representation of a transformation from a value of type a in a context c to a monadic value of type m b.
The Translate type is the basis of the entire KURE library.
Instances
| (Category (Translate c m), Monad m) => Arrow (Translate c m) | The |
| (Arrow (Translate c m), MonadPlus m) => ArrowZero (Translate c m) | The |
| (ArrowZero (Translate c m), MonadPlus m) => ArrowPlus (Translate c m) | The |
| (Arrow (Translate c m), Monad m) => ArrowApply (Translate c m) | The |
| Monad m => Category (Translate c m) | The |
| (Category (Translate c m), MonadCatch m) => CategoryCatch (Translate c m) | The |
| Monad m => Monad (Translate c m a) | Lifting through a Reader transformer, where (c,a) is the read-only environment. |
| Functor m => Functor (Translate c m a) | Lifting through a Reader transformer, where (c,a) is the read-only environment. |
| (Monad (Translate c m a), MonadPlus m) => MonadPlus (Translate c m a) | Lifting through a Reader transformer, where (c,a) is the read-only environment. |
| (Functor (Translate c m a), Applicative m) => Applicative (Translate c m a) | Lifting through a Reader transformer, where (c,a) is the read-only environment. |
| (Applicative (Translate c m a), Alternative m) => Alternative (Translate c m a) | Lifting through a Reader transformer, where (c,a) is the read-only environment. |
| (Monad (Translate c m a), MonadCatch m) => MonadCatch (Translate c m a) | Lifting through a Reader transformer, where (c,a) is the read-only environment. |
| (Monad m, Monoid b) => Monoid (Translate c m a b) | Lifting through the |
type Rewrite c m a = Translate c m a aSource
A Translate that shares the same source and target type.
contextfreeT :: (a -> m b) -> Translate c m a bSource
Build a Translate that doesn't depend on the context.
contextonlyT :: (c -> m b) -> Translate c m a bSource
Build a Translate that doesn't depend on the value.
mapT :: (Traversable t, Monad m) => Translate c m a b -> Translate c m (t a) (t b)Source
Map a Translate over a list.
sideEffectR :: Monad m => (c -> a -> m ()) -> Rewrite c m aSource
An identity Rewrite with side-effects.
Bi-directional Translations
data BiTranslate c m a b Source
An undirected Translate.
Instances
| Monad m => Category (BiTranslate c m) |
type BiRewrite c m a = BiTranslate c m a aSource
A BiTranslate that shares the same source and target type.
bidirectional :: Translate c m a b -> Translate c m b a -> BiTranslate c m a bSource
Construct a BiTranslate from two opposite Translates.
forewardT :: BiTranslate c m a b -> Translate c m a bSource
Extract the foreward Translate from a BiTranslate.
backwardT :: BiTranslate c m a b -> Translate c m b aSource
Extract the backward Translate from a BiTranslate.
whicheverR :: MonadCatch m => BiRewrite c m a -> Rewrite c m aSource
Try the BiRewrite forewards, then backwards if that fails.
Useful when you know which rule you want to apply, but not which direction to apply it in.
invert :: BiTranslate c m a b -> BiTranslate c m b aSource
Invert the forewards and backwards directions of a BiTranslate.
Lenses
A Lens is a way to focus on a sub-structure of type b from a structure of type a.
Instances
| Monad m => Category (Lens c m) | |
| (Category (Lens c m), MonadCatch m) => CategoryCatch (Lens c m) | A |
lens :: Translate c m a ((c, b), b -> m a) -> Lens c m a bSource
The primitive way of building a Lens.
If the unfocussing function is applied to the value focussed on then it should succeed,
and produce the same value as the original argument (of type a).
testLensT :: MonadCatch m => Lens c m a b -> Translate c m a BoolSource
Check if the focusing succeeds, and additionally whether unfocussing from an unchanged value would succeed.
bidirectionalL :: Monad m => BiTranslate c m a b -> Lens c m a bSource
Construct a Lens from a BiTranslate.