kure-2.4.2: Combinators for Strategic Programming

Portabilityghc
Stabilitybeta
MaintainerNeil Sculthorpe <neil@ittc.ku.edu>
Safe HaskellSafe-Inferred

Language.KURE.Injection

Contents

Description

This module provides a type class for injective functions (and their retractions), and some useful interactions with Translate.

A particularly useful instance of Injection is from a to Generic a, and that case is the primary purpose of most of these combinators.

Synopsis

Injection Class

class Injection a b whereSource

A class of injective functions from a to b, and their retractions. The following law is expected to hold:

 retract (inject a) == Just a

Methods

inject :: a -> bSource

retract :: b -> Maybe aSource

Instances

Injection a a

There is an identity injection for all types.

Injection a (Maybe a) 

Monad Injections

injectM :: (Monad m, Injection a a') => a -> m a'Source

Injects a value and lifts it into a Monad.

retractM :: (MonadCatch m, Injection a a') => a' -> m aSource

Retracts a value and lifts it into a MonadCatch, with the possibility of failure.

Translate Injections

injectT :: (Monad m, Injection a a') => Translate c m a a'Source

Lifted inject.

retractT :: (MonadCatch m, Injection a a') => Translate c m a' aSource

Lifted retract, the Translate fails if the retraction fails.

extractT :: (Monad m, Injection a a') => Translate c m a' b -> Translate c m a bSource

Convert a Translate over an injected value into a Translate over a non-injected value.

promoteT :: (MonadCatch m, Injection a a') => Translate c m a b -> Translate c m a' bSource

Promote a Translate over a value into a Translate over an injection of that value, (failing if that injected value cannot be retracted).

promoteWithFailMsgT :: (MonadCatch m, Injection a a') => String -> Translate c m a b -> Translate c m a' bSource

As promoteT, but takes a custom error message to use if promotion fails.

Rewrite Injections

extractR :: (MonadCatch m, Injection a a') => Rewrite c m a' -> Rewrite c m aSource

Convert a Rewrite over an injected value into a Rewrite over a retraction of that value, (failing if that injected value cannot be retracted).

promoteR :: (MonadCatch m, Injection a a') => Rewrite c m a -> Rewrite c m a'Source

Promote a Rewrite into over a value into a Rewrite over an injection of that value, (failing if that injected value cannot be retracted).

extractWithFailMsgR :: (MonadCatch m, Injection a a') => String -> Rewrite c m a' -> Rewrite c m aSource

As extractR, but takes a custom error message to use if extraction fails.

promoteWithFailMsgR :: (MonadCatch m, Injection a a') => String -> Rewrite c m a -> Rewrite c m a'Source

As promoteR, but takes a custom error message to use if promotion fails.

Lens Injections

injectL :: (MonadCatch m, Injection a a') => Lens c m a a'Source

A Lens to the injection of a value.

retractL :: (MonadCatch m, Injection a a') => Lens c m a' aSource

A Lens to the retraction of a value.