Stephen Tetley schrieb:
On 2 March 2010 19:20, Sean Leather <leat...@cs.uu.nl> wrote:

My question is simple:

   How do you rewrite your code to improve it?



Hi Sean - excellent question!

Some things I do...

Quite often I do a 'worker-wrapper-lite' rewrite i.e. change a
function to perform its recursive work in a step rather than calling
the function again with all the arguments, e.g.


para :: (a -> ([a], b) -> b) -> b -> [a] -> b
para phi b = step
   where step []     = b
         step (x:xs) = phi x (xs, step xs)


rather than...

para_ :: (a -> ([a], b) -> b) -> b -> [a] -> b
para_ phi b []     = b
para_ phi b (x:xs) = phi x (xs, para_ phi b xs)

I'm doing no type changing to improve efficiency so it isn't a real
worker-wrapper, but I usually find the 'step' style more pleasing,
especially when the code is somewhat more complicated than the
paramorphism above.
Me too.
http://haskell.org/haskellwiki/Top-level_vs._local_recursion

I have written some articles in Category:Style on that topic.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to