haskoin-util-0.0.1: Utility functions for the Network.Haskoin project

Safe HaskellSafe-Inferred

Network.Haskoin.Util.BuildMonad

Contents

Description

The Build type, and associated operations.

Synopsis

Build monad

data Build a Source

The Build monad represents computations that can be in one of three states:

  • Complete
  • Partial
  • Broken

It extends the Either monad with an additional Partial value to describe a valid computation flagged with a Partial context. The Build monad is useful when you describe computations where parts of the computation are either complete, partially complete or broken. Combining only Complete computations will produce a Complete result. However, if one of the computations is Partial, the whole computation will be Partial as well. And if some computation is Broken, the whole computation will be broken as well.

The Build monad is used by Haskoin to describe the state of the transaction signing computation. To sign a transaction, all input scripts need to be signed. The whole transaction will be completely signed only if all the input scripts are completely signed. If any of the inputs is partially signed, then the whole transaction will be partially signed as well. And the whole transaction is broken if one of the inputs failed to parse or is broken.

Constructors

Complete

Describes a successful complete computation

Fields

runBuild :: a
 
Partial

Describes a successful but partial computation

Fields

runBuild :: a
 
Broken

Describes a broken computation

Fields

runBroken :: String
 

Instances

Monad Build 
Functor Build 
Eq a => Eq (Build a) 
Show a => Show (Build a) 
Arbitrary a => Arbitrary (Build a) 

isComplete :: Build a -> BoolSource

Returns True if the Build value is Complete

isPartial :: Build a -> BoolSource

Returns True if the Build value is Partial

isBroken :: Build a -> BoolSource

Return True if the Build value is Broken

eitherToBuild :: Either String a -> Build aSource

Transforms an Either String value into a Build value. Right is mapped to Complete and Left is mapped to Broken

buildToEither :: Build a -> Either String aSource

Transforms a Build value into an Either String value. Complete and Partial are mapped to Right and Broken is mapped to Left.

guardPartial :: Bool -> Build ()Source

Binds a Partial value to the computation when the predicate is False.

BuildT transformer monad

newtype BuildT m a Source

BuildT transformer monad

Constructors

BuildT 

Fields

runBuildT :: m (Build a)
 

Instances

MonadTrans BuildT 
Monad m => Monad (BuildT m) 
Functor m => Functor (BuildT m) 
MonadIO m => MonadIO (BuildT m) 

liftBuild :: Monad m => Build a -> BuildT m aSource

Lift a Build computation into the BuildT monad