]> gitweb.michael.orlitzky.com - numerical-analysis.git/blobdiff - src/Roots/Fast.hs
src/Roots/Fast.hs: fix monomorphism restriction warnings.
[numerical-analysis.git] / src / Roots / Fast.hs
index 8b69786379218b12448b114d4183ca9c3ef64c5d..a879950556623fbcc1334fc133abc49ca7c6da30 100644 (file)
@@ -1,24 +1,31 @@
 {-# LANGUAGE RebindableSyntax #-}
+{-# LANGUAGE ScopedTypeVariables #-}
 
 -- | The Roots.Fast module contains faster implementations of the
 --   'Roots.Simple' algorithms. Generally, we will pass precomputed
 --   values to the next iteration of a function rather than passing
 --   the function and the points at which to (re)evaluate it.
 
-module Roots.Fast
+module Roots.Fast (
+  bisect,
+  fixed_point_iterations,
+  fixed_point_with_iterations,
+  has_root,
+  trisect )
 where
 
-import Data.List (find)
-import Data.Maybe (fromMaybe)
+import Data.List ( find )
+import Data.Maybe ( fromMaybe )
 
-import Normed
+import Normed ( Normed(..) )
+
+import NumericPrelude hiding ( abs )
+import qualified Algebra.Absolute as Absolute ( C )
+import qualified Algebra.Additive as Additive ( C )
+import qualified Algebra.Algebraic as Algebraic ( C )
+import qualified Algebra.RealRing as RealRing ( C )
+import qualified Algebra.RealField as RealField ( C )
 
-import NumericPrelude hiding (abs)
-import qualified Algebra.Absolute as Absolute
-import qualified Algebra.Additive as Additive
-import qualified Algebra.Algebraic as Algebraic
-import qualified Algebra.RealRing as RealRing
-import qualified Algebra.RealField as RealField
 
 has_root :: (RealField.C a,
              RealRing.C b,
@@ -142,7 +149,7 @@ fixed_point_iterations =
 --
 --   We also return the number of iterations required.
 --
-fixed_point_with_iterations :: (Normed a,
+fixed_point_with_iterations :: forall a b. (Normed a,
                                 Additive.C a,
                                 RealField.C b,
                                 Algebraic.C b)
@@ -159,12 +166,13 @@ fixed_point_with_iterations f epsilon x0 =
     abs_diff v w = norm (v - w)
 
     -- The nth entry in this list is the absolute value of x_{n} -
-    -- x_{n+1}.
-    differences = zipWith abs_diff xn xn_plus_one
+    -- x_{n+1}. They're of type "b" because we're going to compare
+    -- them against epsilon.
+    differences = zipWith abs_diff xn xn_plus_one :: [b]
 
     -- This produces the list [(n, xn)] so that we can determine
     -- the number of iterations required.
-    numbered_xn = zip [0..] xn
+    numbered_xn = zip [0..] xn :: [(Int,a)]
 
     -- A list of pairs, (xn, |x_{n} - x_{n+1}|).
     pairs = zip numbered_xn differences