1 {-# LANGUAGE RebindableSyntax #-}
3 -- | Stuff for which I'm too lazy to come up with a decent name.
9 import Algebra.ToInteger
11 -- | Partition the interval [@a@, @b@] into @n@ subintervals, which we
12 -- then return as a list of pairs.
16 -- >>> partition 1 (-1) 1
19 -- >>> partition 4 (-1) 1
20 -- [(-1.0,-0.5),(-0.5,0.0),(0.0,0.5),(0.5,1.0)]
22 partition :: (Algebra.Field.C a, Algebra.ToInteger.C b, Enum b)
23 => b -- ^ The number of subintervals to use, @n@
24 -> a -- ^ The \"left\" endpoint of the interval, @a@
25 -> a -- ^ The \"right\" endpoint of the interval, @b@
27 -- Somebody asked for zero subintervals? Ok.
30 | n < 0 = error "partition: asked for a negative number of subintervals"
32 [ (xi, xj) | k <- [0..n-1],
33 let k' = fromIntegral k,
35 let xj = a + (k'+1)*h ]
37 h = (b-a)/(fromIntegral $ toInteger n)