
Well, *I* for one liked Lennart's version:
How about?
euler :: (Num a) => (a -> a -> a) -> a -> a -> [a] euler f' dt f0 = euler' f0 0 where euler' f t = f : euler' fnext (t + dt) where fnext = f + dt * (f' f t)
-- Lennart
My attempt to use a where clause used more variables than I needed, methinks. But I'm skeptical about Jerzy's code:
GENTLEMEN! What happened to you?! Why all of you are so incredibly wasteful? Full three (or even four...) lines for just that?
Here you have a one-liner:
euler f' dt f0 = map snd (iterate (\(t,f)->(t+dt,f+dt*f' t f)) (0,f0) )
{snip}
Jerzy Karczmarczuk Caen, France
Is this likely to result in a faster program, especially what with an optimising compiler like GHC? I mean, a one-line version is nice, but the longer ones seem more intuitive to me. (I also play with Python, whose philosophy is that expressiveness is more important than the absolute minimum of code.) Jyrinx jyrinx@mindspring.com