X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FRealFunction.hs;h=01e34bdf39d086e7dbced9690ba6c7a891cda844;hb=8c7f684c5b1a6941a552d2101aff70fe1f9a23ec;hp=cf98029a5f4948d71375ca0e8c188e19a2d39527;hpb=248880a645548e5d1910814dd9023e2af80e16ac;p=spline3.git diff --git a/src/RealFunction.hs b/src/RealFunction.hs index cf98029..01e34bd 100644 --- a/src/RealFunction.hs +++ b/src/RealFunction.hs @@ -1,6 +1,10 @@ {-# LANGUAGE FlexibleInstances #-} -module RealFunction +module RealFunction ( + RealFunction, + cmult, + fexp + ) where @@ -34,12 +38,37 @@ 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)