[Haskell-cafe] Clearly, Haskell is ill-founded

Derek Elkins derek.a.elkins at gmail.com
Sun Jul 15 21:48:11 EDT 2007


On Mon, 2007-07-16 at 02:29 +0100, Conor McBride wrote:
> Hi
> 
> Whoops! Only just spotted this. Many apologies.
> 
> On 10 Jul 2007, at 20:35, Creighton Hogg wrote:
> 
> > Me:
> 
> > > No, an
> > > operating system is supposed to remain responsive. And that's what
> > > total coprograms do.
> >
> > I'm sorry, but can you expand a little further on this?  I guess I  
> > don't understand how a corecursion => responsive to input but not  
> > terminating.  Where does the idea of waiting for input fit into  
> > corecursion?
> >
> 
> 
> You'll be needing a bit of higher-order corecursion for that.
> Here's a coprogram for haskell-cafe:
> 
>  > data{-codata-} Punter = Speak String (String -> Punter)
> 
> A Punter is guaranteed to ask a question, and whatever answer you give
> them, they've always got another question, forever! Meanwhile, a
> String -> Punter is a good-natured soul, always up for answering  
> questions.
> Hence haskell-cafe is a productive coprogram(*) producing a stream of  
> questions
> and answers!
> 
>  > data{-codata-} Stream x = x :> (Stream x)
> 
>  > cafe :: Punter -> (String -> Punter) -> Stream (String, String)
>  > cafe (Speak question learn) guru =
>  >   let  Speak answer guru' = guru question
>  >   in   (question, answer) :> (cafe (learn answer) guru')

If the Punter asks the appropriate question, perhaps the guru will spend
the rest of time thinking about an answer.



More information about the Haskell-Cafe mailing list