Skip to content

Latest commit

 

History

History
37 lines (25 loc) · 1.71 KB

0004-use-handle-to-model-effects.md

File metadata and controls

37 lines (25 loc) · 1.71 KB

4. Use Handle to model Effects

Date: 2021-06-08

Status

Accepted

Context

  • Given we are structuring Hydra node as a reactive core we need a way to ensure a strict separation of pure and impure (or effectful) code
  • Various patterns have been proposed in Haskell to model effects:
    • Tagless final encoding also known as MTL-style although using typeclasses to implement is not necessary, whereby Effect(s) are expressed as typeclass(es) which are propagated as constraints
    • Free monads, or any variant thereof like Eff, freer, extensible-effects, whereby effect(s) are expressed as ADTs which are interpreted in the context of an Effect stack
    • Handle pattern also known as record-of-functions whereby effects are grouped together in a datatype with a single record constructor
  • All options considered have both advocates and detractors and there is no widely accepted pattern
  • We did a couple experiments to explore various options

Decision

  • Effectful components of the Hydra node will be defined using the Handle pattern

Consequences

Effects

  • For example, the on-chain component is defined as:
 newtype OnChain m = OnChain
 { postTx :: MonadThrow m => OnChainTx -> m ()
 }
  • Instantiation to concrete IO is pushed at the outermost layer, eg. in the Main or tests

Additional comments

  • These tradeoffs also appear in other functional languages like F#