[Haskell] Re: Monads vs. continuations

Chung-chieh Shan ccshan at post.harvard.edu
Mon Oct 31 13:23:42 EST 2005

Gregory Woodhouse <gregory.woodhouse at sbcglobal.net> wrote in article <A7137C2A-EE7E-48E9-82F8-6CB87AF8E780 at sbcglobal.net> in gmane.comp.lang.haskell.general:
> Okay, this seems sensible enough. Loosely speaking, I see this code  
> as getting a line, checking to see if it's empty. If it is, it just  
> quits (returning the "empty" value). Otherwise, it prints line, and  
> invokes itself through a *new* do statement. That seems awfully like  
> using a continuation to track the input stream as part of the  
> environment. But it seems obvious to me that here is something I'm  
> not understanding here. I think of the do as providing an appropriate  
> continuation (one in which the line just read is gone) to pass to the  
> next call.

Given your understanding of continuations, it may be more appropriate
for you to think in terms of not "do" but the underlying combinations
of "return" and ">>=" that "do" is syntactic sugar for.  It may also
help to consider monads other than IO, for example the input and
output monads described in Section 7.3 of Philip Wadler's article
"Comprehending Monads".  I suspect that your understanding described
in the paragraph above is essentially correct.  You can also find more
information on the relation between continuations and monads in:

  - Section 7.4 of "Combinations Monads",
  - Andrzej Filinski's articles "Representing Monads" and "Representing
    Layered Monads", and his dissertation "Controlling Effects",
  - Philip Wadler's article "Monads and Composable Continuations",
  - Section 3.2 of Philip Wadler's article "How to Declare an

Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
2005-11-06 Against Exploiting the Environment in War http://tinyurl.com/adhg9
2005-11-20 Universal Children's Day http://www.un.org/depts/dhl/children_day/
2005-11-25 Elimination of Violence Against Women http://tinyurl.com/drd57
2005-11-25 Buy Nothing Day http://www.buynothingday.co.uk/

More information about the Haskell mailing list