X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FRealFunction.hs;h=6a557a9f0f4d4bdb33df42485d84ae02e57cabe5;hb=618a8b60f67939be66ee7298ae4a47522c83f449;hp=834c27a7c0a7fa5b811daeaaa6de1caf5ca62664;hpb=569d6f0f57afccafa5bb4c39e23fcf5e6a77bc03;p=spline3.git diff --git a/src/RealFunction.hs b/src/RealFunction.hs index 834c27a..6a557a9 100644 --- a/src/RealFunction.hs +++ b/src/RealFunction.hs @@ -6,12 +6,22 @@ where type RealFunction a = (a -> Double) + +-- | A 'Show' instance is required to be a 'Num' instance. instance Show (RealFunction a) where - show _ = "Real Function" + -- | There is nothing of value that we can display about a + -- function, so simply print its type. + show _ = "RealFunction" + +-- | An 'Eq' instance is required to be a 'Num' instance. instance Eq (RealFunction a) where + -- | Nothing else makes sense here; always return 'False'. _ == _ = False + +-- | The 'Num' instance for RealFunction allows us to perform +-- arithmetic on functions in the usual way. instance Num (RealFunction a) where (f1 + f2) x = (f1 x) + (f2 x) (f1 - f2) x = (f1 x) - (f2 x) @@ -22,12 +32,14 @@ instance Num (RealFunction a) where fromInteger i _ = fromInteger i --- Takes a constant, and a function as arguments. Returns a new --- function representing the original function times the constant. +-- | Takes a constant, and a function as arguments. Returns a new +-- function representing the original function times the constant. cmult :: Double -> (RealFunction a) -> (RealFunction a) cmult coeff f = (*coeff) . f --- Takes a function f and an exponent n. Returns a new function, f^n. + +-- | Takes a function f and an exponent n. Returns a new function, +-- f^n. fexp :: (RealFunction a) -> Int -> (RealFunction a) fexp f n | n == 0 = (\_ -> 1)