Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. More simple continuation questions (martin)
2. Re: More simple continuation questions (John Wiegley)
----------------------------------------------------------------------
Message: 1
Date: Tue, 15 Jul 2014 20:32:31 +0200
From: martin <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] More simple continuation questions
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-15
Hello all,
(1) when reading about continuations, there is this thing which needs an "other
function" to be passed to produce a
final result. And there is this "other function". Which of the two is "the
continuation"?
http://stackoverflow.com/questions/9050725/call-cc-implementation sais
" ... instead, they are passed a function that represents the 'next step' in
the computation - the 'continuation' "
Which sound like the "other function" is called "continuation". But other
articles hint in the opposite direction.
(2) When comparing continuations with callbacks, it struck me that the type is
newtype Cont r a = Cont { runCont :: (a -> r) -> r }
So the type of the final result is r. But why does the function (a->r) need to
return an r? With regular callbacks this
does not seem to be the case. After returning from the callback the surrounding
function is free to do anything it wants
with the return value and return a value of a different type. Why is that so?
------------------------------
Message: 2
Date: Tue, 15 Jul 2014 22:06:03 -0500
From: "John Wiegley" <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] More simple continuation questions
Message-ID: <[email protected]>
Content-Type: text/plain
>>>>> martin <[email protected]> writes:
> (1) when reading about continuations, there is this thing which needs an
> "other function" to be passed to produce a
> final result. And there is this "other function". Which of the two is "the
> continuation"?
Say you have two functions, foo and bar:
foo :: a -> b
bar :: b -> c
Ordinarily we'd just compose these, like so:
bar . foo
But there are times when this is not desired or possible. In those cases, we
can change foo to accept a continuation instead:
foo :: a -> (b -> r) -> r
'foo' doesn't know what type the continuation will want to return, nor should
it care. So we just leave the result polymorphic, and call it 'r' for result.
Now we can call foo and pass it a "continuation": that is, the thing it should
do next with the value generated from 'foo':
foo bar
Note that we can encode 'foo' a little more conveniently now as:
foo :: a -> Cont r b
This allows us to use the CPS'd (continuation passing style) form of foo as a
Functor, Monad, etc.
John
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 73, Issue 12
*****************************************