[Haskell-cafe] Code review: efficiency question

Brian Hulley brianh at metamilk.com
Mon May 1 19:12:48 EDT 2006


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. 



More information about the Haskell-Cafe mailing list