0

The continuation monad, if written in Scala, is basically

opaque type Cont[R, +A] = (A => R) => R

This type signature, (A => R) => R, is suspiciously similar to foreach in Traversable/Future etc:

def foreach[R](f: A => R) => Unit

If written in a lambda form, and assuming R =:= Unit, this is (A => Unit) => Unit, which is a continuation of return type Unit.

I do not fully understand the connection here: can we safely consider Traversable/Observables as continuations which admits a callback function A => Unit?

Tongfei Chen
  • 613
  • 4
  • 14
  • No, they're not similar at all. You are missing that `forEach` is a *method* which takes an instance as its invisible zeroth parameter. – Bergi Jan 20 '19 at 19:42
  • @Bergi I know that -- the `this` traversable would just be the continuation instance. Given `xs: Traversable[A]`, would `xs.foreach` be a continuation monad? – Tongfei Chen Jan 20 '19 at 19:45

0 Answers0