From 807d976941a8dd426ecf43b18b876413a58384f2 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 20 Feb 2013 14:31:41 -0500 Subject: [PATCH] Make the partition function work with numeric-prelude. --- src/Misc.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Misc.hs b/src/Misc.hs index 4d8f3e7..24fd5b7 100644 --- a/src/Misc.hs +++ b/src/Misc.hs @@ -1,7 +1,13 @@ +{-# LANGUAGE RebindableSyntax #-} + -- | Stuff for which I'm too lazy to come up with a decent name. module Misc where +import NumericPrelude +import Algebra.Field +import Algebra.ToInteger + -- | Partition the interval [@a@, @b@] into @n@ subintervals, which we -- then return as a list of pairs. -- @@ -13,7 +19,7 @@ where -- >>> partition 4 (-1) 1 -- [(-1.0,-0.5),(-0.5,0.0),(0.0,0.5),(0.5,1.0)] -- -partition :: (RealFrac a, Integral b) +partition :: (Algebra.Field.C a, Algebra.ToInteger.C b, Enum b) => b -- ^ The number of subintervals to use, @n@ -> a -- ^ The \"left\" endpoint of the interval, @a@ -> a -- ^ The \"right\" endpoint of the interval, @b@ @@ -28,4 +34,4 @@ partition n a b let xi = a + k'*h, let xj = a + (k'+1)*h ] where - h = fromRational $ (toRational (b-a))/(toRational n) + h = (b-a)/(fromIntegral $ toInteger n) -- 2.43.2