module Ix ( Ix(range, index, inRange, rangeSize) ) where
class Ord a => Ix a where
range :: (a,a) -> [a]
index :: (a,a) -> a -> Int
inRange :: (a,a) -> a -> Bool
rangeSize :: (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
range (l,u) !! index (l,u) i == i -- when i is in range
inRange (l,u) i == i `elem` range (l,u)
map index (range (l,u)) == [0..rangeSize (l,u)]
It is possible to derive an instance of Ix automatically, using a deriving clause on a data declaration (Section 4.3.3). Such derived instance declarations for the class Ix are only possible for enumerations (i.e. datatypes having only nullary constructors) and single-constructor datatypes, whose constituent types are instances of Ix. A Haskell implementation must provide Ix instances for tuples up to at least size 15.
Derivation of Ix instances