Feb. 18th, 2019

xacid: (Default)
import cats._
import cats.implicits._
import scala.annotation.tailrec
import scala.util.control.TailCalls._

object IxCont {
  type ~[A] = TailRec[A]
  type =>>[A, B] = A => ~[B]

  case class Cont[R1, R2, A](cont: ~[(A =>> R2) =>> R1]) extends AnyVal {
    def map[B](f: A => B): Cont[R1, R2, B] = ContIxMonad.map(this)(f)
    def flatMap[R3, B](f: A => Cont[R2, R3, B]): Cont[R1, R3, B] = ContIxMonad.bind(this)(f)
  }

  def ret[S, A](a: A): Cont[S, S, A] = Cont(done(_ (a)))
  def reset[R, A](c: Cont[R, A, A]): R = c.cont.flatMap(_ (done)).result
  def shift[R, B, A](f: (A =>> B) =>> R): Cont[R, B, A] = Cont(done(f(_)))
  def suspend[A, B]: Cont[A =>> B, B, A] = shift(done[A =>> B])
Read more... )

Profile

xacid: (Default)
xacid

April 2021

S M T W T F S
    123
45678910
11121314151617
18192021222324
252627282930 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 20th, 2025 04:19 pm
Powered by Dreamwidth Studios