Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Trampolining the state monad via applicative combinator appears to work
import scalaz._, Scalaz._
def setS(i: Int): State[List[Int], Unit] = modify(i :: _)
val s = (1 to 10000).foldLeft(state[List[Int], Unit](()).lift[Free.Trampoline]) {
case (st, i) => st *> setS(i).lift[Free.Trampoline]
// Purposely choosing not to traverse here for demonstration purposes
val s2 = (1 to 10000).foldLeft(state[List[Int], List[Unit]](List.empty).lift[Free.Trampoline]) {
case (st, i) => (st |@| setS(i).lift[Free.Trampoline])((xs, x) => x :: xs)
val s3 = (1 to 10000).toList.traverseU {
i => setS(i).lift[Free.Trampoline]

This comment has been minimized.

Show comment Hide comment

drstevens Jun 10, 2014

For some reason the applicative works


drstevens commented Jun 10, 2014

For some reason the applicative works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment