data Interval Interval Double Double type Step Double input Double Dou

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
data Interval = Interval Double Double
type Step = Double
input :: ( [ (Double -> Double) ], [Double], Interval, Step)
input = ( [f1, f2], [f1_, f2_], interval, step)
where
f1 x = (30 + 5 * x**2) / (24 - 2*x)
f2 = (40 -) . (7 *)
interval = Interval 1 6
f1_ = 2.5
f2_ = 22
step = 0.001
argsteps :: Interval -> Step -> [Double]
argsteps (Interval left right) step
| abs left > right = []
| otherwise = left : argsteps (Interval (left + step) right) step
maxmin = mm maximum minimum
minmax = mm minimum maximum
mm :: ([(Double, Double)] -> (Double, Double)) -> ([Double] -> Double) -> [(Double->Double)] -> [Double] -> Interval -> Step -> (Double, Double)
mm f1 f2 funcs fs_ interval step = f1 [ (f x, x) | x <- args ]
where args = argsteps interval step
f x = f2 [func x | (func, func_) <- zip funcs fs_]
do_stuff = [f funcs fs_ interval step | f <- [maxmin, minmax]]
where (funcs, fs_, interval, step) = input