[EMAIL PROTECTED] 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
recursion.

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.
[snip]

The scales have tipped in balance of the elegant mapM_ version! :-)

Thanks, Brian.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to