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. Re: More simple continuation questions - pipe analogy (martin)
2. Re: More simple continuation questions - pipe analogy
(John Wiegley)
----------------------------------------------------------------------
Message: 1
Date: Thu, 17 Jul 2014 21:13:14 +0200
From: martin <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] More simple continuation questions -
pipe analogy
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Am 07/16/2014 05:06 AM, schrieb John Wiegley:
>>>>>> 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
I see.
I just wondered if unix pipes are a way to get intuition about continuations.
Is the following about correct?
flip ($) turns an ordinary value into a Cont. In bash you can achieve the same
by prepending "echo" and appending |. So
flip ($) 42
corresponds to
echo 42 |
That expression "echo 42 |" needs another function behind the pipe symbol to
return a value. The equivalent to "id" is
"cat". So "flip ($) 42 id" is corresponds to "echo 42 | cat".
I am still struggeling with the naming. If "cat" is the continuation of "echo
42", what is "echo 42" called (the thing
which needs a continuation)?
Anyways
The unix pipe can also be modeled by simple function composition. I can write a
longer pipe, e.g.
echo 42 | wc | cat
as
cat . wc $ 42 (assuming there were functions cat and id in haskell)
I have trouble to understand what continuations give me byound that. I suspect
the following:
A pipeline is a fixed set of functions, whereas with CPS I can say: if the
value received is this, then continue this
way, otherwise continue that way. With a simple pipeline I would have to put
all these cases into the function which
makes this decision and even pass the decision on to the next function in the
pipeline so it know how we got there. Is
this about right?
Finally, how about the call stack? Are these all tail calls, and I don't have
to worry?
------------------------------
Message: 2
Date: Thu, 17 Jul 2014 19:11:12 -0500
From: "John Wiegley" <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] More simple continuation questions -
pipe analogy
Message-ID: <[email protected]>
Content-Type: text/plain
>>>>> martin <[email protected]> writes:
> A pipeline is a fixed set of functions, whereas with CPS I can say: if the
> value received is this, then continue this way, otherwise continue that
> way. With a simple pipeline I would have to put all these cases into the
> function which makes this decision and even pass the decision on to the next
> function in the pipeline so it know how we got there. Is this about right?
It's not only about right, I've implemented the concept here:
http://hackage.haskell.org/package/simple-conduit
This uses a short-circuiting continuation data type underneath:
newtype Source m a = Source (forall r. Cont (r -> EitherT r m r) a)
And then provides you with the capability to build Unix-style pipelines in
order to keep memory use constant, and to ensure that all resources are freed
when the pipeline finishes, or if it should short-circuit or fail.
I have to look into why the Haddocks are failing to build, but they will build
for you locally.
John
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 73, Issue 13
*****************************************