[Haskell-cafe] Confused about types

Henning Thielemann lemming at henning-thielemann.de
Wed Oct 5 10:42:51 EDT 2005


On Fri, 30 Sep 2005, Lanny Ripple wrote:

> newton_h, next_x_h, dy_h :: (Fractional a, Ord a) => (a -> a) ->
> a -> a -> a
> newton_h f x h = until ((<= h) . abs . f) (next_x_h f h) x

 If this shall be more than a disposable example, I suggest to separate
the Newton iteration from the abort of the iteration. Newton's method
could return a list of the interim results, a sequence in the mathematical
sense.
  newton :: Fractional a => (a -> (a,a)) -> a -> [a]
 The function would compute both the value and the derivative,
  e.g. (\x -> (sin x, cos x))

 Then you can easily apply various implementations of a numeric limit.
  limit :: [a] -> a
   The most simple implementation is certainly: limit = (!!100)

 Eventually a function
  numericDiff :: Fractional a => a -> (a -> a) -> (a -> (a,a))
   could extend a function by some difference quotient.




More information about the Haskell-Cafe mailing list