KC | 14 Aug 03:06 2012
Picon

Tuples & Lists

"This part of the conditional can be written more succinctly as:

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 it could be done as a tuple.

all (== test_lcv) (init_lcv, update_lcv, update_lcv')

_______________________________________________
Haskell mailing list
Haskell <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell
Brandon Allbery | 14 Aug 04:48 2012
Picon

Re: Tuples & Lists

On Mon, Aug 13, 2012 at 9:06 PM, KC <kc1956 <at> gmail.com> wrote:

"This part of the conditional can be written more succinctly as:

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?

Haskell tuples don't work that way, and if they did they would be no better than lists.  You may be thinking of Python tuples, which are more like Haskell's lists (whereas Python's lists are somewhat more like Haskell's arrays).

--
brandon s allbery                                      allbery.b <at> gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms

_______________________________________________
Haskell mailing list
Haskell <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell
Dan Burton | 14 Aug 05:09 2012
Picon

Re: Tuples & Lists

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
_______________________________________________
Haskell mailing list
Haskell <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell

Gmane