1 {-# LANGUAGE TypeSynonymInstances #-}
7 type RealFunction a = (a -> Double)
9 instance Show (RealFunction a) where
10 show _ = "Real Function"
12 instance Eq (RealFunction a) where
15 instance Num (RealFunction a) where
16 (f1 + f2) x = (f1 x) + (f2 x)
17 (f1 - f2) x = (f1 x) - (f2 x)
18 (f1 * f2) x = (f1 x) * (f2 x)
19 (negate f) x = -1 * (f x)
21 (signum f) x = signum (f x)
22 fromInteger i _ = fromInteger i
25 -- Takes a constant, and a function as arguments. Returns a new
26 -- function representing the original function times the constant.
27 cmult :: Double -> (RealFunction a) -> (RealFunction a)
28 cmult coeff f = (*coeff) . f
30 -- Takes a function f and an exponent n. Returns a new function, f^n.
31 fexp :: (RealFunction a) -> Int -> (RealFunction a)
34 | otherwise = \x -> (f x)^n