[Haskell-cafe] Re: question - which monad to use?

Henning Thielemann lemming at henning-thielemann.de
Wed Oct 4 08:08:47 EDT 2006


On Mon, 2 Oct 2006 apfelmus at quantentunnel.de wrote:

> *d) reconsider your definition of f, separate concerns *
> The fact that the computation of ck depends on the iteration count j
> makes me suspicious. If you are using j for convergence tests etc. only,
> then it's not good.
> The most elegant way is to separate concerns: first generate an infinite
> list of approximations
>
>     f :: Double -> Double -> Double
>     f c0 ck = {c_{k+1}}
>
>     cs = iterate (f c0)
>
> and then look for convergence
>
>     epsilon = 1e-12
>     takeUntilConvergence []  = []
>     takeUntilConvergence [x] = [x]
>     takeUntilConvergence (x:x2:xs) =
>         if abs (x - x2) <= epsilon
>             then [x]
>             else x:takeUntilConvergence (x2:xs)


Once more:
 http://www.cs.chalmers.se/~rjmh/Papers/whyfp.html


More information about the Haskell-Cafe mailing list