X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FRealFunction.hs;h=307a0f0c5cb9596a58d8c6375ee9b06fbd79266c;hb=2ff335e99a1e12628b87037e08740fbb241413a6;hp=d461ae2f7d95fd1babe673d576c185bcee1e8de4;hpb=3f7331f579118687cd73b977ce6aa7d401f88a09;p=spline3.git diff --git a/src/RealFunction.hs b/src/RealFunction.hs index d461ae2..307a0f0 100644 --- a/src/RealFunction.hs +++ b/src/RealFunction.hs @@ -3,8 +3,7 @@ module RealFunction ( RealFunction, cmult, - fexp - ) + fexp ) where @@ -38,13 +37,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