"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')
On Mon, Aug 13, 2012 at 9:06 PM, KC <kc1956@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@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms
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-Li... {-# 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#id... 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
participants (3)
-
Brandon Allbery -
Dan Burton -
KC