1 -- | Stuff for which I'm too lazy to come up with a decent name.
5 -- | Partition the interval [@a@, @b@] into @n@ subintervals, which we
6 -- then return as a list of pairs.
10 -- >>> partition 1 (-1) 1
13 -- >>> partition 4 (-1) 1
14 -- [(-1.0,-0.5),(-0.5,0.0),(0.0,0.5),(0.5,1.0)]
16 partition :: (RealFrac a, Integral b)
17 => b -- ^ The number of subintervals to use, @n@
18 -> a -- ^ The \"left\" endpoint of the interval, @a@
19 -> a -- ^ The \"right\" endpoint of the interval, @b@
21 -- Somebody asked for zero subintervals? Ok.
24 | n < 0 = error "partition: asked for a negative number of subintervals"
26 [ (xi, xj) | k <- [0..n-1],
27 let k' = fromIntegral k,
29 let xj = a + (k'+1)*h ]
31 h = fromRational $ (toRational (b-a))/(toRational n)