Proposed additions to Data.Map: lookupFloor and lookupCeiling
leon.p.smith at gmail.com
Mon Mar 1 03:40:18 EST 2010
On Mon, Mar 1, 2010 at 2:39 AM, Sean Leather <leather at cs.uu.nl> wrote:
> It seems more intuitive to reverse the naming. The key parameter to
> lookupFloor is actually the ceiling, and the key returned is the greatest
> key less than or equal to the ceiling. Since there is no floor involved
> here, I would call the function lookupCeiling.
The greatest number less than something would be the floor. :-)
ghci> let map = Map.fromList [ (x, ()) | x <- [0,10..1000] ]
ghci> lookupFloor 75 map
Just (70, ())
ghci> floor 7.5
ghci> lookupCeiling 115 map
ghci> ceiling 11.5
But honestly I almost invariably get the definitions of floor and
ceiling wrong unless I stop to think for a few seconds. I've trained
myself to do that. ;-) Maybe a few examples in the haddocks would
be in order. That's easier to comprehend, if you know approximately
what it should do.
Also, it occurs to me that maybe a combined function :: (Ord k) => k
-> Map k v -> (Maybe k v, Maybe k v) would be useful in addition to
or in place of lookupFloor and lookupCeiling. But I'm not sure.
More information about the Libraries