Skip to content

Instantly share code, notes, and snippets.

@drstevens
Forked from travisbrown/trampolined-state.scala
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save drstevens/3ea464446ee59463af1e to your computer and use it in GitHub Desktop.

Select an option

Save drstevens/3ea464446ee59463af1e to your computer and use it in GitHub Desktop.
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.flatMap(_ => setS(i).lift[Free.Trampoline])
}
s(Nil)
@drstevens
Copy link
Author

For some reason the applicative works

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