]> gitweb.michael.orlitzky.com - spline3.git/blobdiff - src/RealFunction.hs
src/RealFunction.hs: ignore orphan instance warnings.
[spline3.git] / src / RealFunction.hs
index 14afb910e523a2ba611e7ef3d50317cbbf7ffdb4..37babf6b7fc351c1ac6621b2eaa4ce0e8962b056 100644 (file)
@@ -1,9 +1,15 @@
-{-# LANGUAGE TypeSynonymInstances #-}
+{-# OPTIONS_GHC -Wno-orphans #-}
+{-# LANGUAGE FlexibleInstances #-}
 
-module RealFunction
+module RealFunction (
+  RealFunction,
+  cmult,
+  fexp )
 where
 
-
+-- Presumably this is faster without a newtype wrapper, and that's why
+-- we're about to define a bunch of orphan instances below. Note the
+-- GHC pragma thingy at the top of this file to ignore those warnings.
 type RealFunction a = (a -> Double)
 
 
@@ -34,13 +40,38 @@ instance Num (RealFunction a) where
 
 -- | Takes a constant, and a function as arguments. Returns a new
 --   function representing the original function times the constant.
+--
+--   ==== __Examples__
+--
+--   >>> let square x = x**2
+--   >>> square 1
+--   1.0
+--   >>> square 2
+--   4.0
+--   >>> let f = cmult 2 square
+--   >>> f 1
+--   2.0
+--   >>> f 2
+--   8.0
+--
 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,
+--   @g@, defined by g(x) = (f(x))^n. This is /not/ @f@ composed
+--   with itself @n@ times.
+--
+--   ==== __Examples__
+--
+--   >>> let square x = x**2
+--   >>> square 2
+--   4.0
+--   >>> let f = fexp square 3
+--   >>> f 2
+--   64.0
+--
 fexp :: (RealFunction a) -> Int -> (RealFunction a)
 fexp f n
-     | n == 0 = (\_ -> 1)
+     | n == 0 = const 1
      | otherwise = \x -> (f x)^n