kure-2.16.6: Combinators for Strategic Programming

Copyright(c) 2012--2014 The University of Kansas
LicenseBSD3
MaintainerNeil Sculthorpe <neil@ittc.ku.edu>
Stabilitybeta
Portabilityghc
Safe HaskellSafe-Inferred
LanguageHaskell2010

Language.KURE.Injection

Contents

Description

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

Synopsis

Injection Class

class Injection a b where Source

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

project (inject a) == Just a

Methods

inject :: a -> b Source

project :: b -> Maybe a Source

Instances

Injection a a

There is an identity injection for all types.

Injection a (Maybe a) 

Monad Injections

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

Injects a value and lifts it into a Monad.

projectM :: (Monad m, Injection a g) => g -> m a Source

Projects a value and lifts it into a Monad, with the possibility of failure.

projectWithFailMsgM :: (Monad m, Injection a g) => String -> g -> m a Source

As projectM, but takes a custom error message to use if projection fails.

Transformation Injections

injectT :: (Monad m, Injection a g) => Transform c m a g Source

Lifted inject.

projectT :: (Monad m, Injection a g) => Transform c m g a Source

Lifted project, the transformation fails if the projection fails.

extractT :: (Monad m, Injection a g) => Transform c m g b -> Transform c m a b Source

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

promoteT :: (Monad m, Injection a g) => Transform c m a b -> Transform c m g b Source

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

promoteWithFailMsgT :: (Monad m, Injection a g) => String -> Transform c m a b -> Transform c m g b Source

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

Rewrite Injections

extractR :: (Monad m, Injection a g) => Rewrite c m g -> Rewrite c m a Source

Convert a rewrite over an injected value into a rewrite over a projection of that value, (failing if that injected value cannot be projected).

promoteR :: (Monad m, Injection a g) => Rewrite c m a -> Rewrite c m g Source

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

extractWithFailMsgR :: (Monad m, Injection a g) => String -> Rewrite c m g -> Rewrite c m a Source

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

promoteWithFailMsgR :: (Monad m, Injection a g) => String -> Rewrite c m a -> Rewrite c m g Source

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