Free Monad
Video: Dead-Simple Dependency Injection in #Scala with @runarorama from the 2012 #NEScala Symposium - http://t.co/ULfIcsJM
2012-03-28 05:23:06@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@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@runarorama ... or do you just use them in totally different situations?
2012-03-28 09:06:37@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@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@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@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@runarorama btw, please reply in haiku form. 140 characters is not sufficiently limiting.
2012-03-28 11:53:20@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@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@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@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@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@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@mergeconflict Yeah, you get constant stack since running the free monad is tail-recursive.
2012-03-29 08:02:29@mergeconflict Free[Get * Put, A] is a nice replacement for State, yes.
2012-03-29 08:03:09@mergeconflict type Trivial[A] = Unit; type Option[A] = Free[Trivial, A]
2012-03-29 08:04:07