This page is no longer maintained — Please continue to the home page at www.scala-lang.org

thanks

No replies
Luc Duponcheel
Joined: 2008-12-19,
User offline. Last seen 34 weeks 3 days ago.
Hi,

just wanted to say thanks

this group rocks:

a few days ago I did not know about
how Scala implemented delimited continuations
and now I have cool code that I can present next week
at the Brussels University !!!


every monad (having a flatMap method)
can be given a method:

  def reflect[Y]: X @cps[C[Y]] = {
   shift {
    flatMap((_: X => C[Y]))
   }

and it's surrounding
monad module (having a _return method)
can be given a method:

 def _cartProd[X, Y]
  (left: Monad[X], right: Monad[Y]) =
   reset {
    _return {
     (left.reflect[(X, Y)],
      right.reflect[(X, Y)])
    }
   }

and then (using my ListMonad monad instance) I can test

  val cartProdTest: C[(Int, String)] =
   _cartProd(
     ListMonad[Int](1 :: 2 :: 3 :: Nil),
     ListMonad[String]("a" :: "b" :: "c" :: Nil)
    )

  println {
   cartProdTest.run(())
  }

and run

$ run.sh UsingMonads
List((1,a), (1,b), (1,c), (2,a), (2,b), (2,c), (3,a), (3,b), (3,c))


cool!

thx

Luc

--
   __~O
  -\ <,
(*)/ (*)

reality goes far beyond imagination

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland