I remember reading a tutorial that pointed out that you can often
avoid explicit recusion in Haskell and instead use higher-level
operators.
For your code, I think
drawModals = foldr (flip (>>)) (return ()) . map drawModal
works(?).
On 5/2/06, Brian Hulley <[EMAIL PROTECTED]> wrote:
Hi -
I started off writing the following piece of monadic code:
let
drawModal :: Control -> ManagerM ()
drawModal c = do -- details omitted
-- Prolog style coding...
drawModals :: [Control] -> ManagerM ()
drawModals [] = return ()
drawModals (c:cs) = do
drawModals cs
drawModal c
drawModals cs
then it struck me that I should have not bothered with drawModals and
instead should just have used:
mapM_ drawModal (reverse cs)
However, while this looks more elegant, it is less efficient?
In other words, how much optimization can one assume when writing Haskell
code?
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.
Any ideas?
Thanks, Brian.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe