Skip to content

Instantly share code, notes, and snippets.

View ymdfield's full-sized avatar

Riyo ymdfield

  • Tokyo, Japan
  • 12:47 (UTC +09:00)
  • X @ymdfield
View GitHub Profile
@marcinzh
marcinzh / CatchFail.scala
Created May 28, 2025 13:38
CatchFail.hs translated to Scala 3 and Turbolift
//> using scala "3.3.5"
//> using dep "io.github.marcinzh::turbolift-core:0.112.0"
//> using dep "io.github.marcinzh::turbolift-bindless:0.112.0"
/*********************************************************************************************
How to run:
1. Ensure you have Java 11 or newer
2. Install scala-cli
3. Execute `scala-cli <link-to-this-gist>`
Link to the original:

Monads and delimited control are very closely related, so it isn’t too hard to understand them in terms of one another. From a monadic point of view, the big idea is that if you have the computation m >>= f, then f is m’s continuation. It’s the function that is called with m’s result to continue execution after m returns.

If you have a long chain of binds, the continuation is just the composition of all of them. So, for example, if you have

m >>= f >>= g >>= h

then the continuation of m is f >=> g >=> h. Likewise, the continuation of m >>= f is g >=> h.