Module
Run
- Package
- purescript-run
- Repository
- natefaubion/purescript-run
#Run Source
newtype Run (r :: Row Type) a
An extensible effect Monad, indexed by a set of effect functors. Effects
are eliminated by interpretation into a pure value or into some base
effect Monad. The Run
Monad is an alternative to Monad Transformers,
and can represent both associative and non-associative effects.
An example using State
and Except
:
type MyEffects =
( state ∷ STATE Int
, except ∷ EXCEPT String
, base ∷ BaseEff (console ∷ CONSOLE)
)
yesProgram ∷ Run MyEffects Unit
yesProgram = do
whenM (gets (_ < 0)) do
throw "Number is less than 0"
whileM_ (gets (_ > 0)) do
liftEff $ log "Yes"
modify (_ - 1)
main =
yesProgram
# catch (liftEff <<< log)
# runState 10
# runBase
# void
Instances
Re-exports from Data.Functor.Variant
#default Source
default :: forall r b a. a -> VariantF r b -> a
Combinator for partial matching with a default value in case of failure.
caseFn :: forall r. VariantF (foo :: FProxy Maybe, bar :: FProxy (Tuple String) | r) Int -> String
caseFn = default "No match"
# on (SProxy :: SProxy "foo") (\foo -> "Foo: " <> maybe "nothing" show foo)
# on (SProxy :: SProxy "bar") (\bar -> "Bar: " <> show (snd bar))
#case_ Source
case_ :: forall b a. VariantF () a -> b
Combinator for exhaustive pattern matching.
caseFn :: VariantF (foo :: FProxy Maybe, bar :: FProxy (Tuple String), baz :: FProxy (Either String)) Int -> String
caseFn = case_
# on (SProxy :: SProxy "foo") (\foo -> "Foo: " <> maybe "nothing" show foo)
# on (SProxy :: SProxy "bar") (\bar -> "Bar: " <> show (snd bar))
# on (SProxy :: SProxy "baz") (\baz -> "Baz: " <> either id show baz)