From: Michael Orlitzky Date: Fri, 7 Dec 2018 15:47:20 +0000 (-0500) Subject: src/Integration/Trapezoid.hs: fix monomorphism restriction warning. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=38b68b8c9b83fc7bc9c6a2c9535a50a904d20b08;p=numerical-analysis.git src/Integration/Trapezoid.hs: fix monomorphism restriction warning. --- diff --git a/src/Integration/Trapezoid.hs b/src/Integration/Trapezoid.hs index df4da78..807bbc5 100644 --- a/src/Integration/Trapezoid.hs +++ b/src/Integration/Trapezoid.hs @@ -1,4 +1,5 @@ {-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE RebindableSyntax #-} module Integration.Trapezoid ( @@ -36,15 +37,15 @@ import qualified Algebra.ToRational as ToRational ( C ) -- >>> trapezoid_1 f (-1) 1 -- 2.0 -- -trapezoid_1 :: (Field.C a, ToRational.C a, Field.C b) +trapezoid_1 :: forall a b. (Field.C a, ToRational.C a, Field.C b) => (a -> b) -- ^ The function @f@ -> a -- ^ The \"left\" endpoint, @a@ -> a -- ^ The \"right\" endpoint, @b@ -> b -trapezoid_1 f a b = - (((f a) + (f b)) / 2) * coerced_interval_length +trapezoid_1 f x y = + (((f x) + (f y)) / 2) * coerced_interval_length where - coerced_interval_length = fromRational' $ toRational (b - a) + coerced_interval_length = fromRational' $ toRational (y - x) :: b -- | Use the composite trapezoid rule to numerically integrate @f@ -- over @n@ subintervals of [@a@, @b@].