1 -----------------------------------------------------------------------------
4 -- Copyright : (c) The University of Glasgow 2001
5 -- License : BSD-style (see the file libraries/base/LICENSE)
7 -- Maintainer : libraries@haskell.org
9 -- Portability : portable
11 -- The 'Ix' class is used to map a contiguous subrange of values in
12 -- type onto integers. It is used primarily for array indexing
13 -- (see the array package).
15 -----------------------------------------------------------------------------
20 ( range -- :: (Ix a) => (a,a) -> [a]
21 , index -- :: (Ix a) => (a,a) -> a -> Int
22 , inRange -- :: (Ix a) => (a,a) -> a -> Bool
23 , rangeSize -- :: (Ix a) => (a,a) -> Int
33 -- (Ix a, Ix b) => Ix (a, b)
36 -- Implementation checked wrt. Haskell 98 lib report, 1/99.
38 -- * Deriving Instances of 'Ix'
39 -- | Derived instance declarations for the class 'Ix' are only possible
40 -- for enumerations (i.e. datatypes having only nullary constructors)
41 -- and single-constructor datatypes, including arbitrarily large tuples,
42 -- whose constituent types are instances of 'Ix'.
44 -- * For an enumeration, the nullary constructors are assumed to be
45 -- numbered left-to-right with the indices being 0 to n-1 inclusive. This
46 -- is the same numbering defined by the 'Enum' class. For example, given
49 -- > data Colour = Red | Orange | Yellow | Green | Blue | Indigo | Violet
53 -- > range (Yellow,Blue) == [Yellow,Green,Blue]
54 -- > index (Yellow,Blue) Green == 1
55 -- > inRange (Yellow,Blue) Red == False
57 -- * For single-constructor datatypes, the derived instance declarations
58 -- are as shown for tuples in Figure 1
59 -- <http://www.haskell.org/onlinelibrary/ix.html#prelude-index>.
65 #ifdef __GLASGOW_HASKELL__
70 import Hugs.Prelude( Ix(..) )