[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-4.9.0.0/docs/src/GHC.Base.html#thenIO>
(IO m <https://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627396262>)
k <https://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627396263>
= IO (\ s <https://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627396264>
-> case m <https://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627396262>
s <https://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627396264>
of (# new_s <https://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627396265>,
_ #) -> unIO <https://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#unIO>
k <https://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627396263>
new_s <https://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627396265>)


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).

Will
-------------- 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