]> gitweb.michael.orlitzky.com - numerical-analysis.git/blobdiff - src/Integration/Simpson.hs
src/Integration/Simpson.hs: fix monomorphism restriction warnings.
[numerical-analysis.git] / src / Integration / Simpson.hs
index 6bfe258eb8e454b7a9dcc0c7221d4638eed3f61f..afa932b672cee04075a43c52ccacba1e9f56be2c 100644 (file)
@@ -1,14 +1,18 @@
+{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE ScopedTypeVariables #-}
 {-# LANGUAGE RebindableSyntax #-}
 
-module Integration.Simpson
+module Integration.Simpson (
+  simpson,
+  simpson_1 )
 where
 
-import Misc (partition)
+import Misc ( partition )
 
-import NumericPrelude hiding (abs)
-import qualified Algebra.RealField as RealField
-import qualified Algebra.ToInteger as ToInteger
-import qualified Algebra.ToRational as ToRational
+import NumericPrelude hiding ( abs )
+import qualified Algebra.RealField as RealField ( C )
+import qualified Algebra.ToInteger as ToInteger ( C )
+import qualified Algebra.ToRational as ToRational ( C )
 
 -- | Use the Simpson's rule to numerically integrate @f@ over the
 --   interval [@a@, @b@].
@@ -37,16 +41,16 @@ import qualified Algebra.ToRational as ToRational
 --   >>> simpson_1 f 0 1
 --   0.25
 --
-simpson_1 :: (RealField.C a, ToRational.C a, RealField.C b)
+simpson_1 :: forall a b. (RealField.C a, ToRational.C a, RealField.C b)
             => (a -> b) -- ^ The function @f@
             -> a       -- ^ The \"left\" endpoint, @a@
             -> a       -- ^ The \"right\" endpoint, @b@
             -> b
-simpson_1 f a b =
-  coefficient * ((f a) + 4*(f midpoint) + (f b))
+simpson_1 f x y =
+  coefficient * ((f x) + 4*(f midpoint) + (f y))
   where
-    coefficient = fromRational' $ (toRational (b - a)) / 6
-    midpoint = (a + b) / 2
+    coefficient = fromRational' $ (toRational (y - x)) / 6 :: b
+    midpoint = (x + y) / 2
 
 
 -- | Use the composite Simpson's rule to numerically integrate @f@