]> gitweb.michael.orlitzky.com - spline3.git/blobdiff - src/RealFunction.hs
Remove some dead code.
[spline3.git] / src / RealFunction.hs
index 5e0832d24d515ea750c7452ee0f2e336d07d4f5b..d461ae2f7d95fd1babe673d576c185bcee1e8de4 100644 (file)
@@ -1,33 +1,49 @@
-{-# LANGUAGE TypeSynonymInstances #-}
+{-# LANGUAGE FlexibleInstances #-}
 
-module RealFunction
+module RealFunction (
+  RealFunction,
+  cmult,
+  fexp
+  )
 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
-    _ == _ = False
+    -- | Nothing else makes sense here; always return 'False'.
+    _ == _ = error "You can't compare functions for equality."
 
+
+-- | 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)
-    f1 * f2  = \x -> (f1 x) * (f2 x)
-    negate f = \x -> -1 * (f x)
-    abs    f = \x -> abs (f x)
-    signum f = \x -> signum (f x)
-    fromInteger i = \_ -> (fromInteger i)    
+    (f1 + f2)  x = (f1 x) + (f2 x)
+    (f1 - f2)  x = (f1 x) - (f2 x)
+    (f1 * f2)  x = (f1 x) * (f2 x)
+    (negate f) x = -1 * (f x)
+    (abs    f) x = abs (f x)
+    (signum f) x = signum (f x)
+    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)