[Haskell-cafe] Code review: efficiency question
brianh at metamilk.com
Mon May 1 21:08:08 EDT 2006
ajb at spamcop.net wrote:
> I suspect it depends how long the list is. The original drawModals
> would probably be more efficient for small lists, because it doesn't
> require creating an intermediate list. OTOH, it may well be less
> efficient for longer lists because it can't take advantage of tail
Thanks for pointing this out - I'd forgotten all about the impact of having
non-tail recursion, so my original Prolog-style code was not necessarily
more efficient anyway, since it may be cheaper to allocate list elements
than to allocate activation records for recursion.
>> I'm trying to get a rough idea so I can decide whether to write
>> helper functions such as drawModals in future or whether I should
>> always just use the most elegant code instead.
> This is a question that is independent of Haskell. You should ALWAYS
> write the most elegant code first, and only make it uglier if it's not
> fast enough.
The scales have tipped in balance of the elegant mapM_ version! :-)
More information about the Haskell-Cafe