97
Eric Torreborre The Eff monad One monad to rule them all!

The Eff monad, one monad to rule them all

Embed Size (px)

Citation preview

Page 1: The Eff monad, one monad to rule them all

Eric Torreborre

The Eff monad

One monad to rule them all!

Page 2: The Eff monad, one monad to rule them all
Page 3: 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

Page 4: The Eff monad, one monad to rule them all
Page 5: The Eff monad, one monad to rule them all

You could have invented monads!

Page 6: The Eff monad, one monad to rule them all
Page 7: The Eff monad, one monad to rule them all
Page 8: The Eff monad, one monad to rule them all

Exceptions?

Page 9: The Eff monad, one monad to rule them all

Exceptions?

Page 10: The Eff monad, one monad to rule them all

State?

Page 11: The Eff monad, one monad to rule them all

State?

Page 12: The Eff monad, one monad to rule them all

Genius!

Page 13: The Eff monad, one monad to rule them all

Can we have both state and error?

Page 14: The Eff monad, one monad to rule them all

First idea: stack them!

Page 15: The Eff monad, one monad to rule them all

1996!

Page 16: The Eff monad, one monad to rule them all

Which order?

Page 17: The Eff monad, one monad to rule them all

DOES NOT WORK!

Page 18: The Eff monad, one monad to rule them all

THIS ONE WORKS!

Page 19: The Eff monad, one monad to rule them all

DIFFERENCE?

Page 20: The Eff monad, one monad to rule them all

DIFFERENCE?

Page 21: The Eff monad, one monad to rule them all

DIFFERENCE?

Page 22: The Eff monad, one monad to rule them all

ORDER IS

IMPORTANT!

Page 23: The Eff monad, one monad to rule them all

GENERALISE

Page 24: The Eff monad, one monad to rule them all

STACKING HAS A COST!

Page 25: The Eff monad, one monad to rule them all
Page 26: The Eff monad, one monad to rule them all
Page 27: The Eff monad, one monad to rule them all
Page 28: The Eff monad, one monad to rule them all

SIMILAR EFFECTS?

Page 29: The Eff monad, one monad to rule them all

IN PRACTICE

Page 30: The Eff monad, one monad to rule them all

Specialized stacks

Page 31: The Eff monad, one monad to rule them all

Specialized functions

Page 32: The Eff monad, one monad to rule them all

WHAT IF?

We need to use both Hadoop and S3?

Page 33: The Eff monad, one monad to rule them all
Page 34: The Eff monad, one monad to rule them all
Page 35: The Eff monad, one monad to rule them all
Page 36: The Eff monad, one monad to rule them all
Page 37: The Eff monad, one monad to rule them all
Page 38: The Eff monad, one monad to rule them all

WHAT ELSE?

Page 39: The Eff monad, one monad to rule them all

WHAT ELSE?

Page 40: The Eff monad, one monad to rule them all

Type-level

effects

Eff monadValue-level

effects

ContinuationsInterprete

rs

Member typeclas

s

Page 41: The Eff monad, one monad to rule them all

Effect

Page 42: The Eff monad, one monad to rule them all

Type-level effects

Value-level effects

Page 43: The Eff monad, one monad to rule them all

Value-level effect

Continuation

s

Page 44: The Eff monad, one monad to rule them all

Option Interpreter

State Interpreter

Continuation1

Continuation2

Option Interpreter Continuation3 +

State Interpreter

Page 45: The Eff monad, one monad to rule them all

OPTION RELOADED

Page 46: The Eff monad, one monad to rule them all
Page 47: The Eff monad, one monad to rule them all

KLEISLI

Page 48: The Eff monad, one monad to rule them all
Page 49: The Eff monad, one monad to rule them all

OPTION AS EFFECT

Page 50: The Eff monad, one monad to rule them all

EFF

Page 51: The Eff monad, one monad to rule them all
Page 52: The Eff monad, one monad to rule them all
Page 53: The Eff monad, one monad to rule them all
Page 54: The Eff monad, one monad to rule them all

ERROR AS EFFECT

Page 55: The Eff monad, one monad to rule them all
Page 56: The Eff monad, one monad to rule them all

NEVER RE-IMPLEMENT flatMap

EVER AGAIN!

Page 57: The Eff monad, one monad to rule them all

EFFECTS UNITE!

Page 58: The Eff monad, one monad to rule them all

Type-level effects

Page 59: The Eff monad, one monad to rule them all

Value-level effects

Page 60: The Eff monad, one monad to rule them all

Value-level effects

Page 61: The Eff monad, one monad to rule them all

Member typeclass

Page 62: The Eff monad, one monad to rule them all
Page 63: The Eff monad, one monad to rule them all
Page 64: The Eff monad, one monad to rule them all
Page 65: The Eff monad, one monad to rule them all
Page 66: The Eff monad, one monad to rule them all
Page 67: The Eff monad, one monad to rule them all

LIBRARY

Page 68: The Eff monad, one monad to rule them all
Page 69: The Eff monad, one monad to rule them all
Page 70: The Eff monad, one monad to rule them all

scalaz.Future

Page 71: The Eff monad, one monad to rule them all
Page 72: The Eff monad, one monad to rule them all
Page 73: The Eff monad, one monad to rule them all

STACKOVERFLOW:-(

Page 74: The Eff monad, one monad to rule them all

STACK SAFE

Page 75: The Eff monad, one monad to rule them all
Page 76: The Eff monad, one monad to rule them all

TRANSFORM EFFECTS

Page 77: The Eff monad, one monad to rule them all
Page 78: The Eff monad, one monad to rule them all
Page 79: The Eff monad, one monad to rule them all

SO, SILVER BULLET?

Page 80: The Eff monad, one monad to rule them all

SORRYNO

Page 81: The Eff monad, one monad to rule them all

Implicits

Page 82: The Eff monad, one monad to rule them all
Page 83: The Eff monad, one monad to rule them all

ImplicitsUse it in prod'

RenamingsCheck laws

Missing functionsBenchmarking, Scalajs...

Page 84: The Eff monad, one monad to rule them all

CREDITS

Page 86: The Eff monad, one monad to rule them all

THANKS!

Page 87: The Eff monad, one monad to rule them all
Page 88: The Eff monad, one monad to rule them all

Matchers

Page 89: The Eff monad, one monad to rule them all

Matchers

Page 90: The Eff monad, one monad to rule them all

Matchers

Page 91: The Eff monad, one monad to rule them all

Matchers

Page 92: The Eff monad, one monad to rule them all

MORE TROUBLE

Page 93: The Eff monad, one monad to rule them all

List(5, 7, 1)

Page 94: The Eff monad, one monad to rule them all

TOO BIG?

Page 95: The Eff monad, one monad to rule them all
Page 96: The Eff monad, one monad to rule them all
Page 97: The Eff monad, one monad to rule them all

ONE MORE ERROR LAYER!