[Haskell-cafe] Strange space leak

William Yager will.yager at gmail.com
Mon Nov 7 22:32:07 UTC 2016

On Mon, Nov 7, 2016 at 4:02 PM, David Feuer <david.feuer at gmail.com> wrote:

> IO m *> n = IO (\ s -> case m s of (# new_s, a #) -> unIO ((const n) a)
> new_s)

>From looking at the Applicative source, this appears to be correct. Why
don't we use thenIO instead, which elides the "const" and has the form

thenIO <https://hackage.haskell.org/package/base->
(IO m <https://hackage.haskell.org/package/base->)
k <https://hackage.haskell.org/package/base->
= IO (\ s <https://hackage.haskell.org/package/base->
-> case m <https://hackage.haskell.org/package/base->
s <https://hackage.haskell.org/package/base->
of (# new_s <https://hackage.haskell.org/package/base->,
_ #) -> unIO <https://hackage.haskell.org/package/base->
k <https://hackage.haskell.org/package/base->
new_s <https://hackage.haskell.org/package/base->)

It doesn't look like thenIO is used or exported, which makes me think
someone either forgot about it or there's some good reason that isn't
documented. Obviously if things go as planned, the const gets reduced away
at compile time, but it seems like if we have thenIO sitting there in the
source we might as well use it and not have to worry about compile-time
eta-reduction of (\_ -> k).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20161107/8dd2a0d3/attachment.html>

More information about the Haskell-Cafe mailing list