Re: [Haskell-cafe] Really Simple explanation of Continuations Needed

2011-10-05 Thread Vinod Grover
On the general notion of continuations, I believe Matt Might's blog explains
it quite well using Javascript.

http://matt.might.net/articles/by-example-continuation-passing-style/

In the way of a simple example, he suggests that instead of writing

function id(x) {
  return x ;
}

a CPS version might write:

function id(x,ret) {
  ret(x) ;
}

etc...

IMO things appear confusing to newbies (it happened to me once too) when
people dont use intuitive names for obvious things like continuations

On Fri, Sep 30, 2011 at 11:42 PM, Mark Spezzano 
mark.spezz...@chariot.net.au wrote:

 Hi,

 Can someone please give me a _lucid_ and  _simple_ explanation of exactly
 how continuations can be used in Haskell?

 I've already had a look at most of the tutorials and explanations on the
 web, but I'm still confused. Continuations and CPS have me baffled. (I have
 most of the Haskell textbooks and even these are sketchy on Continuations)

 I don't understand the notion of the Cont monad and how it can be used for
 multitasking, backtracking and interrupting computations. I understand that
 functions  take in a (continuation) function that represents the work
 remaining to do, but al of the explanations on the web and in technical
 papers seems to trip over themselves in explaining the fundamentals to a
 CPS-newbie.

 If anyone could explain such concepts to me in unambiguous, clear English
 then this would be very helpful.

 Thanks in advance for your help,

 Mark


 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Really Simple explanation of Continuations Needed

2011-10-02 Thread Heinrich Apfelmus

Ozgur Akgun wrote:

On 1 October 2011 11:55, Yves Parès limestr...@gmail.com wrote:


BTW Heinrich, the

evalState (sequence . repeat . State $ \s - (s,s+1)) 0

at the end doesn't work anymore. It should be replaced by :
evalState (sequence . repeat . StateT $ \s - Identity (s,s+1)) 0



Or equivalently:

evalState (sequence . repeat . state $ \s - (s,s+1)) 0


Thanks, I've changed it.


Best regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Really Simple explanation of Continuations Needed

2011-10-01 Thread Mark Spezzano
Hi,

Can someone please give me a _lucid_ and  _simple_ explanation of exactly how 
continuations can be used in Haskell?

I've already had a look at most of the tutorials and explanations on the web, 
but I'm still confused. Continuations and CPS have me baffled. (I have most of 
the Haskell textbooks and even these are sketchy on Continuations)

I don't understand the notion of the Cont monad and how it can be used for 
multitasking, backtracking and interrupting computations. I understand that 
functions  take in a (continuation) function that represents the work remaining 
to do, but al of the explanations on the web and in technical papers seems to 
trip over themselves in explaining the fundamentals to a CPS-newbie.

If anyone could explain such concepts to me in unambiguous, clear English then 
this would be very helpful.

Thanks in advance for your help,

Mark


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Really Simple explanation of Continuations Needed

2011-10-01 Thread Heinrich Apfelmus

Mark Spezzano wrote:

Can someone please give me a _lucid_ and  _simple_ explanation of
exactly how continuations can be used in Haskell?

I've already had a look at most of the tutorials and explanations on
the web, but I'm still confused. Continuations and CPS have me
baffled. (I have most of the Haskell textbooks and even these are
sketchy on Continuations)

I don't understand the notion of the Cont monad and how it can be
used for multitasking, backtracking and interrupting computations. I
understand that functions  take in a (continuation) function that
represents the work remaining to do, but all of the explanations on
the web and in technical papers seems to trip over themselves in
explaining the fundamentals to a CPS-newbie.


If you just want to implement multitasking, backtracking or interrupting 
computations, without continuations, I recommend my Operational Monad 
Tutorial


  http://apfelmus.nfshost.com/articles/operational-monad.html

The link to the Cont monad is explained at the very end.


Best regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Really Simple explanation of Continuations Needed

2011-10-01 Thread Mark Spezzano
Hi Heinrich, 

I'm really looking to use the Cont monad itself--but the link you gave me is 
also helpful, so thank you.

If anyone else has words of wisdom to add to this thread please feel free to 
pitch in.

Thanks,

Mark 

On 01/10/2011, at 5:08 PM, Heinrich Apfelmus wrote:

 Mark Spezzano wrote:
 Can someone please give me a _lucid_ and  _simple_ explanation of
 exactly how continuations can be used in Haskell?
 I've already had a look at most of the tutorials and explanations on
 the web, but I'm still confused. Continuations and CPS have me
 baffled. (I have most of the Haskell textbooks and even these are
 sketchy on Continuations)
 I don't understand the notion of the Cont monad and how it can be
 used for multitasking, backtracking and interrupting computations. I
 understand that functions  take in a (continuation) function that
 represents the work remaining to do, but all of the explanations on
 the web and in technical papers seems to trip over themselves in
 explaining the fundamentals to a CPS-newbie.
 
 If you just want to implement multitasking, backtracking or interrupting 
 computations, without continuations, I recommend my Operational Monad 
 Tutorial
 
  http://apfelmus.nfshost.com/articles/operational-monad.html
 
 The link to the Cont monad is explained at the very end.
 
 
 Best regards,
 Heinrich Apfelmus
 
 --
 http://apfelmus.nfshost.com
 
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Really Simple explanation of Continuations Needed

2011-10-01 Thread Yves Parès
Having worked with the operational-package, I only can recommend it. In fact
I was trying to do the same thing you are now.
The only thing is that operational needs the use of GADTs, which come as an
extension, but still are a useful and heavily used feature.

BTW Heinrich, the

evalState (sequence . repeat . State $ \s - (s,s+1)) 0

at the end doesn't work anymore. It should be replaced by :
evalState (sequence . repeat . StateT $ \s - Identity (s,s+1)) 0


2011/10/1 Mark Spezzano mark.spezz...@chariot.net.au

 Hi Heinrich,

 I'm really looking to use the Cont monad itself--but the link you gave me
 is also helpful, so thank you.

 If anyone else has words of wisdom to add to this thread please feel free
 to pitch in.

 Thanks,

 Mark

 On 01/10/2011, at 5:08 PM, Heinrich Apfelmus wrote:

  Mark Spezzano wrote:
  Can someone please give me a _lucid_ and  _simple_ explanation of
  exactly how continuations can be used in Haskell?
  I've already had a look at most of the tutorials and explanations on
  the web, but I'm still confused. Continuations and CPS have me
  baffled. (I have most of the Haskell textbooks and even these are
  sketchy on Continuations)
  I don't understand the notion of the Cont monad and how it can be
  used for multitasking, backtracking and interrupting computations. I
  understand that functions  take in a (continuation) function that
  represents the work remaining to do, but all of the explanations on
  the web and in technical papers seems to trip over themselves in
  explaining the fundamentals to a CPS-newbie.
 
  If you just want to implement multitasking, backtracking or interrupting
 computations, without continuations, I recommend my Operational Monad
 Tutorial
 
   http://apfelmus.nfshost.com/articles/operational-monad.html
 
  The link to the Cont monad is explained at the very end.
 
 
  Best regards,
  Heinrich Apfelmus
 
  --
  http://apfelmus.nfshost.com
 
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 


 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Really Simple explanation of Continuations Needed

2011-10-01 Thread Ozgur Akgun
Hi.

On 1 October 2011 11:55, Yves Parès limestr...@gmail.com wrote:

 BTW Heinrich, the

 evalState (sequence . repeat . State $ \s - (s,s+1)) 0

 at the end doesn't work anymore. It should be replaced by :
 evalState (sequence . repeat . StateT $ \s - Identity (s,s+1)) 0


Or equivalently:

evalState (sequence . repeat . state $ \s - (s,s+1)) 0

Ozgur
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Really Simple explanation of Continuations Needed

2011-10-01 Thread wren ng thornton

Hello,

Oleg has a introduction for delimited continuations which he presented 
during ICFP:


http://okmij.org/ftp/continuations/index.html#tutorial

Of course, it's worth mentioning that the Cont monad is actually doing 
delimited continuations, cf.:


http://okmij.org/ftp/continuations/ContExample.hs


Ultimately, the idea is simple, which may be part of the reason why it's 
so hard to explain (cf., monads). The short version is that at any point 
in the execution of a program we have some part of the program which has 
already run, and some part which has yet to run; the latter is the 
continuation, which is also often called the calling context. All 
the hoopla about continuations comes from the tricksy things we can do 
once we realize that programs have these two parts instead of only 
thinking about the history of the execution.


Operationally, the way the Cont monad works is that we explicitly build 
up the continuation as a function to be called, and then runCont 
actually applies that function in order to yield a result. What use is 
this? Well, it gives us a version of the goto statement, namely call/cc.


Another part of the problem (other than the simplicity) is that the term 
continuation has many different meanings in computer science. On the 
one hand we have the call/cc notion of continuations, which is what's 
captured by Scheme's call/cc and by the Cont monad. On the other hand we 
have the CPS transformation that many compilers use when optimizing 
code. But the topics of discussion for call/cc and CPS are very 
different, and so it's easy to get confused if you try to think of them 
as the same thing. They are closely related, but they're different 
enough that you should keep them separate until you have some 
understanding of what they're about.


--
Live well,
~wren

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe