llvm-extra-0.8.0.2: Utility functions for the llvm interface

Safe HaskellNone

LLVM.Extra.MaybeContinuation

Description

Maybe transformer datatype implemented in continuation passing style.

Synopsis

Documentation

newtype T r z a Source

Isomorphic to ReaderT (CodeGenFunction r z) (ContT z (CodeGenFunction r)) a, where the reader provides the block for Nothing and the continuation part manages the Just.

Constructors

Cons 

Fields

resolve :: CodeGenFunction r z -> (a -> CodeGenFunction r z) -> CodeGenFunction r z
 

Instances

Monad (T r z) 
Functor (T r z) 
Applicative (T r z) 
MonadIO (T r z) 

map :: (a -> CodeGenFunction r b) -> T r z a -> T r z bSource

withBool :: Phi z => Value Bool -> CodeGenFunction r a -> T r z aSource

counterpart to Data.Maybe.HT.toMaybe

fromBool :: Phi z => CodeGenFunction r (Value Bool, a) -> T r z aSource

fromMaybe :: Phi z => CodeGenFunction r (T a) -> T r z aSource

toMaybe :: Undefined a => T r (T a) a -> CodeGenFunction r (T a)Source

lift :: CodeGenFunction r a -> T r z aSource

guard :: Phi z => Value Bool -> T r z ()Source

just :: a -> T r z aSource

nothing :: T r z aSource

bind :: T r z a -> (a -> T r z b) -> T r z bSource

onFail :: CodeGenFunction r () -> T r z a -> T r z aSource

Run an exception handler if the Maybe-action fails. The exception is propagated. That is, the handler is intended for a cleanup procedure.

alternative :: (Phi z, Undefined a) => T r (T a) a -> T r (T a) a -> T r z aSource

Run the first action and if that fails run the second action. If both actions fail, then the composed action fails, too.

fixedLengthLoop :: (Phi s, Undefined s, Num i, IsConst i, IsInteger i, IsFirstClass i, CmpRet i, CmpResult i ~ Bool) => Value i -> s -> (s -> T r (T s) s) -> CodeGenFunction r (Value i, T s)Source

arrayLoop :: (Phi s, Undefined s, IsType a, Num i, IsConst i, IsInteger i, IsFirstClass i, CmpRet i, CmpResult i ~ Bool) => Value i -> Value (Ptr a) -> s -> (Value (Ptr a) -> s -> T r (T (Value (Ptr a), s)) s) -> CodeGenFunction r (Value i, T s)Source

If the returned position is smaller than the array size, then returned final state is nothing.

arrayLoop2 :: (Phi s, Undefined s, IsType a, IsType b, Num i, IsConst i, IsInteger i, IsFirstClass i, CmpRet i, CmpResult i ~ Bool) => Value i -> Value (Ptr a) -> Value (Ptr b) -> s -> (Value (Ptr a) -> Value (Ptr b) -> s -> T r (T (Value (Ptr a), (Value (Ptr b), s))) s) -> CodeGenFunction r (Value i, T s)Source