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

Aboiut continuation monad

2 replies
sw2wolf
Joined: 2009-07-16,
User offline. Last seen 42 years 45 weeks ago.

trait Value

type Answer = Value;

/**
* A continuation monad.
*/
case class M[A](in: (A => Answer) => Answer) {
def bind[B](k: A => M[B]) = M[B](c => in (a => k(a) in c))
}

what does the bind function mean ? especially i donot understand "M[B](c =>
in (a => k(a) in c)"

Sincerely!

-----
nightmare = unsafePerformIO(getWrongWife >>= sex)

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Aboiut continuation monad
Search for Bind in Haskell-related monad descriptions. I don't know why it was adoped here.   Note that the case class M[A] receives a parameter called "in", which is a function returning Answer and receiving a function (A => Answer) as parameter. So:   M[B](c => in (a => k(a) in c)) = new M[B](parameter) parameter = c => in (a => k(a) in c)) = function receiving "c" as parameter and returning in (a => k(a) in c). in (a => k(a) in c) = call the "in" function defined for the present M object, and pass (a => k(a) in c) as a parameter. Remember hat "in" is a function which receives a funcion as a parameter; a => k(a) in c = function which receives "a", and returns k(a) in c k(a) in c = k(a) returns M[B], and M[B] defines"in". So k(a) in c is the infix notation for k(a).in(c).

  On Thu, Jul 16, 2009 at 11:25 AM, sw2wolf <czsq888 [at] 163 [dot] com> wrote:

trait Value

type Answer = Value;

 /**
  * A continuation monad.
  */
 case class M[A](in: (A => Answer) => Answer) {
   def bind[B](k: A => M[B])  = M[B](c => in (a => k(a) in c))
 }

what does the bind function mean ? especially i donot understand "M[B](c =>
in (a => k(a) in c)"

Sincerely!

-----
nightmare = unsafePerformIO(getWrongWife >>= sex)
--
View this message in context: http://www.nabble.com/Aboiut-continuation-monad-tp24517432p24517432.html
Sent from the Scala - User mailing list archive at Nabble.com.




--
Daniel C. Sobral

Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.
sw2wolf
Joined: 2009-07-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Aboiut continuation monad

k(a) in c is the infix notation for k(a).in(c).
i see now, thanks !

Daniel Sobral wrote:
>
> Search for Bind in Haskell-related monad descriptions. I don't know why it
> was adoped here.
>
> Note that the case class M[A] receives a parameter called "in", which is a
> function returning Answer and receiving a function (A => Answer) as
> parameter. So:
>
> M[B](c => in (a => k(a) in c)) = new M[B](parameter)
> parameter = c => in (a => k(a) in c)) = function receiving "c" as
> parameter
> and returning in (a => k(a) in c).
> in (a => k(a) in c) = call the "in" function defined for the present M
> object, and pass (a => k(a) in c) as a parameter. Remember hat "in" is a
> function which receives a funcion as a parameter;
> a => k(a) in c = function which receives "a", and returns k(a) in c
> k(a) in c = k(a) returns M[B], and M[B] defines"in". So k(a) in c is the
> infix notation for k(a).in(c).
>
>
>
> On Thu, Jul 16, 2009 at 11:25 AM, sw2wolf wrote:
>
>>
>> trait Value
>>
>> type Answer = Value;
>>
>> /**
>> * A continuation monad.
>> */
>> case class M[A](in: (A => Answer) => Answer) {
>> def bind[B](k: A => M[B]) = M[B](c => in (a => k(a) in c))
>> }
>>
>> what does the bind function mean ? especially i donot understand "M[B](c
>> =>
>> in (a => k(a) in c)"
>>
>> Sincerely!
>>
>> -----
>> nightmare = unsafePerformIO(getWrongWife >>= sex)
>> --
>> View this message in context:
>> http://www.nabble.com/Aboiut-continuation-monad-tp24517432p24517432.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>

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