kure-2.0.0: Combinators for Strategic Programming

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

Language.KURE.Combinators

Contents

Description

This module provides various monadic and arrow combinators that are particularly useful when working with translations. Note that these combinators assume that mplus behaves as a catch, for both fail and mzero.

Synopsis

Monad Combinators

guardFail :: Monad m => Bool -> String -> m ()Source

Similar to guard, but using fail rather than mzero.

condM :: Monad m => m Bool -> m a -> m a -> m aSource

if-then-else lifted over a Monad.

whenM :: Monad m => m Bool -> m a -> m aSource

if-then lifted over a Monad.

tryM :: MonadPlus m => a -> m a -> m aSource

Catch a failing monadic computation, making it succeed with a constant value.

mtryM :: (MonadPlus m, Monoid a) => m a -> m aSource

Catch a failing monadic computation, making it succeed with mempty.

attemptM :: MonadPlus m => m a -> m (Maybe a)Source

Catch a failing monadic computation, making it succeed with Nothing.

testM :: MonadPlus m => m a -> m BoolSource

Determine if a monadic computation succeeds.

notM :: MonadPlus m => m a -> m ()Source

Fail if the Monad succeeds; succeed with () if it fails.

Arrow Combinators

The names result and argument are taken from Conal Elliott's semantic editor combinators.

result :: Arrow ~> => (b -> c) -> (a ~> b) -> a ~> cSource

Apply a pure function to the result of an Arrow.

argument :: Arrow ~> => (a -> b) -> (b ~> c) -> a ~> cSource

Apply a pure function to the argument to an Arrow.

idR :: Category ~> => a ~> aSource

Synonym for id.

(<+) :: ArrowPlus ~> => (a ~> b) -> (a ~> b) -> a ~> bSource

Synonym for <+>.

readerR :: ArrowApply ~> => (a -> a ~> b) -> a ~> bSource

Look at the argument to the Arrow before choosing which Arrow to use.

acceptR :: (ArrowZero ~>, ArrowApply ~>) => (a -> Bool) -> a ~> aSource

Look at the argument to an Arrow, and choose to be either the identity arrow or the zero arrow.

tryR :: ArrowPlus ~> => (a ~> a) -> a ~> aSource

Catch a failing ArrowPlus, making it into an identity.

attemptR :: ArrowPlus ~> => (a ~> a) -> a ~> (Bool, a)Source

Catch a failing ArrowPlus, making it succeed with a Boolean flag. Useful when defining anyR instances.

changedR :: (ArrowPlus ~>, ArrowApply ~>, Eq a) => (a ~> a) -> a ~> aSource

Makes an Arrow fail if the result value equals the argument value.

repeatR :: ArrowPlus ~> => (a ~> a) -> a ~> aSource

Repeat an ArrowPlus until it fails, then return the result before the failure. Requires at least the first attempt to succeed.

(>+>) :: (ArrowPlus ~>, ArrowApply ~>) => (a ~> a) -> (a ~> a) -> a ~> aSource

Attempts two Arrowss in sequence, succeeding if one or both succeed.

orR :: (ArrowZero ~>, ArrowPlus ~>, ArrowApply ~>) => [a ~> a] -> a ~> aSource

Sequence a list of Arrows, succeeding if any succeed.

andR :: Arrow ~> => [a ~> a] -> a ~> aSource

Sequence a list of Arrows, succeeding if they all succeed.