kure-0.3.1: Combinators for Strategic Programming

MaintainerAndy Gill <andygill@ku.edu>



This is the definition of the monad inside KURE.



data RewriteM m dec exp Source


(Monoid dec, Monad m) => Monad (RewriteM m dec) 
(Monoid dec, Monad m) => Functor (RewriteM m dec) 
(Monad m, Monoid dec) => Failable (RewriteM m dec) 

data RewriteStatusM dec exp Source


RewriteReturnM exp !(Maybe dec) !Count

a regular success

RewriteFailureM String

a real failure | RewriteIdM exp -- ^ identity marker on a value

data Count Source


Count !Int 


theCount :: Count -> IntSource

How many transformations have been performed?

runRewriteM :: RewriteM m dec exp -> dec -> m (RewriteStatusM dec exp)Source

runRewriteM runs the RewriteM monad, returning a status.

failM :: (Monad m, Monoid dec) => String -> RewriteM m dec aSource

failM is our basic failure, with a String message.

catchM :: Monad m => RewriteM m dec a -> (String -> RewriteM m dec a) -> RewriteM m dec aSource

catchM catches failures, and tries a second monadic computation.

chainM :: (Monoid dec, Monad m) => RewriteM m dec b -> (Int -> b -> RewriteM m dec c) -> RewriteM m dec cSource

chainM executes the first argument then the second, much like >>=, except that the second computation can see if the first computation was an identity or not. Used to spot when a rewrite succeeded, but was the identity.

liftQ :: (Monad m, Monoid dec) => m a -> RewriteM m dec aSource

liftQ lets you tunnel into the inner monad, because RewriteM is actually monad transformer.

markM :: Monad m => RewriteM m dec a -> RewriteM m dec aSource

markM is used to mark a monadic rewrite as a non-identity, unless the congruence flag is set.

transparentlyM :: Monad m => RewriteM m dec a -> RewriteM m dec aSource

transparently sets the congruence flag, such that if the monadic action was identity preserving, then a markM does not set the non-indentity flag.

readEnvM :: (Monad m, Monoid dec) => RewriteM m dec decSource

getDecsM reads the local environment

mapEnvM :: (Monad m, Monoid dec) => (dec -> dec) -> RewriteM m dec a -> RewriteM m dec aSource

mapDecs changes the local environment, inside a local monadic invocation.

writeEnvM :: (Monad m, Monoid dec) => dec -> RewriteM m dec ()Source

writeDecM writes a value to the writer monad inside the RewriteM.