Free Monad

#nescala 2012 での runarorama さんが発表した 「Dead-Simple Dependency Injection」 という発表のFree Monadについてtwitter上で本人が話していたのでまとめた。 http://f.cl.ly/items/2J0v0m0x180X1c1K2E2d/Runar-NEscala-DI.pdf 続きを読む
3
NewCircle @TheNewCircle

Video: Dead-Simple Dependency Injection in #Scala with @runarorama from the 2012 #NEScala Symposium - http://t.co/ULfIcsJM

2012-03-28 05:23:06
mergeconflict @mergeconflict

@runarorama i think i missed an important point somewhere in your #nescala talk: does using Free[_, _] have an advantage over Reader[_, _]?

2012-03-28 08:59:10
mergeconflict @mergeconflict

@runarorama ... and doesn't Reader[KVS, _] fit the description of "a little program that describes what we might do to a KVS if we had one"?

2012-03-28 09:02:34
mergeconflict @mergeconflict

@runarorama ... or do you just use them in totally different situations?

2012-03-28 09:06:37
Rúnar @runarorama

@mergeconflict Yeah, but such a program is totally opaque. Note that Free lets us pass in an immutable map as the store.

2012-03-28 11:06:44
Rúnar @runarorama

@mergeconflict Same for IO and State--the action is opaque. With a free monad, the interpreter can reason about what the program does.

2012-03-28 11:10:54
mergeconflict @mergeconflict

@runarorama i can see that Free[_,_] turns the program inside-out, s.t. the impl of KVS here is externalized, but don't see why it's useful

2012-03-28 11:33:12
mergeconflict @mergeconflict

@runarorama i.e. it was some effort to make our "language" so we may vary its interpreter, but why not State[KVS, _] and vary the KVS impl?

2012-03-28 11:37:57
mergeconflict @mergeconflict

@runarorama btw, please reply in haiku form. 140 characters is not sufficiently limiting.

2012-03-28 11:53:20
Rúnar @runarorama

@mergeconflict 1: A sufficiently long program in State will overflow the stack, whereas Free can be TCOed via a codensity monad.

2012-03-28 21:42:59
Rúnar @runarorama

@mergeconflict 2: Free monads compose in parallel. Free[F, A] and Free[G, A] compose into Free[({type f[x]=Either[F[A],G[A]]})#f, A]

2012-03-28 21:46:16
Rúnar @runarorama

@mergeconflict Ask the same of any free monad. Why are Option and Either useful? How is Iteratee useful? Comes down to ADTs vs interfaces.

2012-03-28 21:48:10
mergeconflict @mergeconflict

@runarorama then i think you undersold Free (pun intended) in your preso. We get const stack like Reader and immutability like State, yeah?

2012-03-29 07:34:03
mergeconflict @mergeconflict

@runarorama and it looks like Free[KVS, _] specifically (with get, put, etc.) is a nice replacement for State if i understand correctly?

2012-03-29 07:36:34
mergeconflict @mergeconflict

@runarorama so you're saying Option is a free monad? Meaning it can be expressed as a Free[Something, _]? What's that something?

2012-03-29 07:38:40
Rúnar @runarorama

@mergeconflict Yeah, you get constant stack since running the free monad is tail-recursive.

2012-03-29 08:02:29
Rúnar @runarorama

@mergeconflict Free[Get * Put, A] is a nice replacement for State, yes.

2012-03-29 08:03:09
Rúnar @runarorama

@mergeconflict type Trivial[A] = Unit; type Option[A] = Free[Trivial, A]

2012-03-29 08:04:07