the eff monad, one monad to rule them all
TRANSCRIPT
Eric Torreborre
The Eff monad
One monad to rule them all!
It must be evident how multifarious and how mutually complicated are the considerations which the working of such an engine involve. There are frequently several distinct sets of effects going on simultaneously; all in a manner independent of each other, and yet to a greater or less degree exercising a mutual influence.
Ada Lovelace,
1842
You could have invented monads!
Exceptions?
Exceptions?
State?
State?
Genius!
Can we have both state and error?
First idea: stack them!
1996!
Which order?
DOES NOT WORK!
THIS ONE WORKS!
DIFFERENCE?
DIFFERENCE?
DIFFERENCE?
ORDER IS
IMPORTANT!
GENERALISE
STACKING HAS A COST!
SIMILAR EFFECTS?
IN PRACTICE
Specialized stacks
Specialized functions
WHAT IF?
We need to use both Hadoop and S3?
WHAT ELSE?
WHAT ELSE?
Type-level
effects
Eff monadValue-level
effects
ContinuationsInterprete
rs
Member typeclas
s
Effect
Type-level effects
Value-level effects
Value-level effect
Continuation
s
Option Interpreter
State Interpreter
Continuation1
Continuation2
Option Interpreter Continuation3 +
State Interpreter
OPTION RELOADED
KLEISLI
OPTION AS EFFECT
EFF
ERROR AS EFFECT
NEVER RE-IMPLEMENT flatMap
EVER AGAIN!
EFFECTS UNITE!
Type-level effects
Value-level effects
Value-level effects
Member typeclass
LIBRARY
scalaz.Future
STACKOVERFLOW:-(
STACK SAFE
TRANSFORM EFFECTS
SO, SILVER BULLET?
SORRYNO
Implicits
ImplicitsUse it in prod'
RenamingsCheck laws
Missing functionsBenchmarking, Scalajs...
CREDITS
LINKSMonads for functional programmingMonad transformers and modular interpreters
Extensible effectsReflection without remorseFreer monad, more extensible effects
THANKS!
Matchers
Matchers
Matchers
Matchers
MORE TROUBLE
List(5, 7, 1)
TOO BIG?
ONE MORE ERROR LAYER!