module Ix ( Ix(range, index, inRange), rangeSize ) where class (Show a, Ord a) => Ix a where range :: (a,a) -> [a] index :: (a,a) -> a -> Int inRange :: (a,a) -> a -> Bool rangeSize :: (Ix a) => (a,a) -> Int instance Ix Char where ... instance Ix Int where ... instance Ix Integer where ... instance (Ix a, Ix b) => Ix (a,b) where ... -- et cetera instance Ix Bool where ... instance Ix Ordering where ... |
An implementation is entitled to assume the following laws about these
operations:
range (l,u) !! index (l,u) i == i -- when i is in range
inRange (l,u) i == i `elem` range (l,u)
Derived instance declarations for the class Ix are only possible for enumerations (i.e. datatypes having only nullary constructors) and single-constructor datatypes, including arbitrarily large tuples, whose constituent types are instances of Ix.