[Haskell] Tuples & Lists

Dan Burton danburton.email at gmail.com
Tue Aug 14 05:09:38 CEST 2012


>
> all (== test_lcv) [init_lcv, update_lcv, update_lcv']"
>
> Wouldn't this be be better as tuple avoiding list overhead or does ghc
> optimize it out?
>
If I'm not mistaken, ghc will optimize it out. From
http://hackage.haskell.org/packages/archive/base/4.5.1.0/doc/html/src/GHC-List.html#all

{-# RULES
 ...
"all/build"     forall p (g::forall b.(a->b->b)->b->b) .
                all p (build g) = g ((&&) . p) True
 #-}

See the docs on List fusion for details (note how "all" is listed as a
"good consumer"):
http://www.haskell.org/ghc/docs/7.4.2/html/users_guide/rewrite-rules.html#id690070

So in fact it may be the case that the tuple version (if it were valid
Haskell) is less efficient because it can't take advantage of list fusion
and has to allocate the tuple instead.

-- Dan Burton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell/attachments/20120813/f7fb8263/attachment.htm>


More information about the Haskell mailing list