+{-# 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.
--
-- >>> 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@
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)