A newbie's proud first code
Tue, 06 Nov 2001 19:06:00 -0800
> > 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)
>> euler f' dt f0 = map snd (iterate (\(t,f)->(t+dt,f+dt*f' t f)) (0,f0) )
Then Jyrinx writes:
>I'm sceptical of Jerzy's code ...
>Is this likely to result in a faster program, especially what with an
>optimising compiler like GHC?
Unless I'm missing some important factor, Jerzy's version will run
as fast with GHC as Lennart's --faster in some contexts, eg, (map (*2)
(euler f' dt f0)), because Jerzy's version is eligible for "fold/build"
For more info, there's a nice paper on this called "A shortcut to
Of course, for Haskell newbies, Lennart's "explicit recursion" version is
easier to understand, unless you are very comfortable with abstraction like
many math types like Jerzy are.