base-4.12.0.0: Basic libraries

Data.Ix

Description

The Ix class is used to map a contiguous subrange of values in type onto integers. It is used primarily for array indexing (see the array package). Ix uses row-major order.

Synopsis

# The Ix class

class Ord a => Ix a where Source #

The Ix class is used to map a contiguous subrange of values in a type onto integers. It is used primarily for array indexing (see the array package).

The first argument (l,u) of each of these operations is a pair specifying the lower and upper bounds of a contiguous subrange of values.

An implementation is entitled to assume the following laws about these operations:

• inRange (l,u) i == elem i (range (l,u)) 
• range (l,u) !! index (l,u) i == i, when inRange (l,u) i
• map (index (l,u)) (range (l,u))) == [0..rangeSize (l,u)-1] 
• rangeSize (l,u) == length (range (l,u)) 

Minimal complete definition

range, (index | unsafeIndex), inRange

Methods

range :: (a, a) -> [a] Source #

The list of values in the subrange defined by a bounding pair.

index :: (a, a) -> a -> Int Source #

The position of a subscript in the subrange.

inRange :: (a, a) -> a -> Bool Source #

Returns True the given subscript lies in the range defined the bounding pair.

rangeSize :: (a, a) -> Int Source #

The size of the subrange defined by a bounding pair.

Instances
 Source # Since: 2.1 Instance detailsDefined in GHC.Arr Methodsrange :: (Bool, Bool) -> [Bool] Source #index :: (Bool, Bool) -> Bool -> Int Source #unsafeIndex :: (Bool, Bool) -> Bool -> IntinRange :: (Bool, Bool) -> Bool -> Bool Source #rangeSize :: (Bool, Bool) -> Int Source #unsafeRangeSize :: (Bool, Bool) -> Int Source # Since: 2.1 Instance detailsDefined in GHC.Arr Methodsrange :: (Char, Char) -> [Char] Source #index :: (Char, Char) -> Char -> Int Source #unsafeIndex :: (Char, Char) -> Char -> IntinRange :: (Char, Char) -> Char -> Bool Source #rangeSize :: (Char, Char) -> Int Source #unsafeRangeSize :: (Char, Char) -> Int Source # Since: 2.1 Instance detailsDefined in GHC.Arr Methodsrange :: (Int, Int) -> [Int] Source #index :: (Int, Int) -> Int -> Int Source #unsafeIndex :: (Int, Int) -> Int -> IntinRange :: (Int, Int) -> Int -> Bool Source #rangeSize :: (Int, Int) -> Int Source #unsafeRangeSize :: (Int, Int) -> Int Source # Since: 2.1 Instance detailsDefined in GHC.Int Methodsrange :: (Int8, Int8) -> [Int8] Source #index :: (Int8, Int8) -> Int8 -> Int Source #unsafeIndex :: (Int8, Int8) -> Int8 -> IntinRange :: (Int8, Int8) -> Int8 -> Bool Source #rangeSize :: (Int8, Int8) -> Int Source #unsafeRangeSize :: (Int8, Int8) -> Int Source # Since: 2.1 Instance detailsDefined in GHC.Int Methodsrange :: (Int16, Int16) -> [Int16] Source #index :: (Int16, Int16) -> Int16 -> Int Source #unsafeIndex :: (Int16, Int16) -> Int16 -> IntinRange :: (Int16, Int16) -> Int16 -> Bool Source #rangeSize :: (Int16, Int16) -> Int Source #unsafeRangeSize :: (Int16, Int16) -> Int Source # Since: 2.1 Instance detailsDefined in GHC.Int Methodsrange :: (Int32, Int32) -> [Int32] Source #index :: (Int32, Int32) -> Int32 -> Int Source #unsafeIndex :: (Int32, Int32) -> Int32 -> IntinRange :: (Int32, Int32) -> Int32 -> Bool Source #rangeSize :: (Int32, Int32) -> Int Source #unsafeRangeSize :: (Int32, Int32) -> Int Source # Since: 2.1 Instance detailsDefined in GHC.Int Methodsrange :: (Int64, Int64) -> [Int64] Source #index :: (Int64, Int64) -> Int64 -> Int Source #unsafeIndex :: (Int64, Int64) -> Int64 -> IntinRange :: (Int64, Int64) -> Int64 -> Bool Source #rangeSize :: (Int64, Int64) -> Int Source #unsafeRangeSize :: (Int64, Int64) -> Int Source # Since: 2.1 Instance detailsDefined in GHC.Arr Methodsrange :: (Integer, Integer) -> [Integer] Source #index :: (Integer, Integer) -> Integer -> Int Source #unsafeIndex :: (Integer, Integer) -> Integer -> IntinRange :: (Integer, Integer) -> Integer -> Bool Source #rangeSize :: (Integer, Integer) -> Int Source #unsafeRangeSize :: (Integer, Integer) -> Int Source # Since: 4.8.0.0 Instance detailsDefined in GHC.Arr Methodsrange :: (Natural, Natural) -> [Natural] Source #index :: (Natural, Natural) -> Natural -> Int Source #unsafeIndex :: (Natural, Natural) -> Natural -> IntinRange :: (Natural, Natural) -> Natural -> Bool Source #rangeSize :: (Natural, Natural) -> Int Source #unsafeRangeSize :: (Natural, Natural) -> Int Source # Since: 2.1 Instance detailsDefined in GHC.Arr Methodsrange :: (Ordering, Ordering) -> [Ordering] Source #index :: (Ordering, Ordering) -> Ordering -> Int Source #unsafeIndex :: (Ordering, Ordering) -> Ordering -> IntinRange :: (Ordering, Ordering) -> Ordering -> Bool Source #rangeSize :: (Ordering, Ordering) -> Int Source #unsafeRangeSize :: (Ordering, Ordering) -> Int Source # Since: 4.6.0.0 Instance detailsDefined in GHC.Arr Methodsrange :: (Word, Word) -> [Word] Source #index :: (Word, Word) -> Word -> Int Source #unsafeIndex :: (Word, Word) -> Word -> IntinRange :: (Word, Word) -> Word -> Bool Source #rangeSize :: (Word, Word) -> Int Source #unsafeRangeSize :: (Word, Word) -> Int Source # Since: 2.1 Instance detailsDefined in GHC.Word Methodsrange :: (Word8, Word8) -> [Word8] Source #index :: (Word8, Word8) -> Word8 -> Int Source #unsafeIndex :: (Word8, Word8) -> Word8 -> IntinRange :: (Word8, Word8) -> Word8 -> Bool Source #rangeSize :: (Word8, Word8) -> Int Source #unsafeRangeSize :: (Word8, Word8) -> Int Source # Since: 2.1 Instance detailsDefined in GHC.Word Methodsrange :: (Word16, Word16) -> [Word16] Source #index :: (Word16, Word16) -> Word16 -> Int Source #unsafeIndex :: (Word16, Word16) -> Word16 -> IntinRange :: (Word16, Word16) -> Word16 -> Bool Source #rangeSize :: (Word16, Word16) -> Int Source #unsafeRangeSize :: (Word16, Word16) -> Int Source # Since: 2.1 Instance detailsDefined in GHC.Word Methodsrange :: (Word32, Word32) -> [Word32] Source #index :: (Word32, Word32) -> Word32 -> Int Source #unsafeIndex :: (Word32, Word32) -> Word32 -> IntinRange :: (Word32, Word32) -> Word32 -> Bool Source #rangeSize :: (Word32, Word32) -> Int Source #unsafeRangeSize :: (Word32, Word32) -> Int Source # Since: 2.1 Instance detailsDefined in GHC.Word Methodsrange :: (Word64, Word64) -> [Word64] Source #index :: (Word64, Word64) -> Word64 -> Int Source #unsafeIndex :: (Word64, Word64) -> Word64 -> IntinRange :: (Word64, Word64) -> Word64 -> Bool Source #rangeSize :: (Word64, Word64) -> Int Source #unsafeRangeSize :: (Word64, Word64) -> Int Ix () Source # Since: 2.1 Instance detailsDefined in GHC.Arr Methodsrange :: ((), ()) -> [()] Source #index :: ((), ()) -> () -> Int Source #unsafeIndex :: ((), ()) -> () -> IntinRange :: ((), ()) -> () -> Bool Source #rangeSize :: ((), ()) -> Int Source #unsafeRangeSize :: ((), ()) -> Int Source # Since: 2.1 Instance detailsDefined in GHC.Unicode Methods Source # Since: 4.2.0.0 Instance detailsDefined in GHC.IO.IOMode Methodsrange :: (IOMode, IOMode) -> [IOMode] Source #index :: (IOMode, IOMode) -> IOMode -> Int Source #unsafeIndex :: (IOMode, IOMode) -> IOMode -> IntinRange :: (IOMode, IOMode) -> IOMode -> Bool Source #rangeSize :: (IOMode, IOMode) -> Int Source #unsafeRangeSize :: (IOMode, IOMode) -> Int Source # Since: 4.9.0.0 Instance detailsDefined in GHC.Generics Methods Source # Since: 4.9.0.0 Instance detailsDefined in GHC.Generics Methods Source # Since: 4.9.0.0 Instance detailsDefined in GHC.Generics Methods Source # Since: 4.9.0.0 Instance detailsDefined in GHC.Generics Methods Source # Since: 4.2.0.0 Instance detailsDefined in GHC.IO.Device Methodsrange :: (SeekMode, SeekMode) -> [SeekMode] Source #index :: (SeekMode, SeekMode) -> SeekMode -> Int Source #unsafeIndex :: (SeekMode, SeekMode) -> SeekMode -> IntinRange :: (SeekMode, SeekMode) -> SeekMode -> Bool Source #rangeSize :: (SeekMode, SeekMode) -> Int Source #unsafeRangeSize :: (SeekMode, SeekMode) -> Int Source # Since: 4.8.0.0 Instance detailsDefined in Data.Void Methodsrange :: (Void, Void) -> [Void] Source #index :: (Void, Void) -> Void -> Int Source #unsafeIndex :: (Void, Void) -> Void -> IntinRange :: (Void, Void) -> Void -> Bool Source #rangeSize :: (Void, Void) -> Int Source #unsafeRangeSize :: (Void, Void) -> Int Ix a => Ix (Identity a) Source # Since: 4.9.0.0 Instance detailsDefined in Data.Functor.Identity Methodsrange :: (Identity a, Identity a) -> [Identity a] Source #index :: (Identity a, Identity a) -> Identity a -> Int Source #unsafeIndex :: (Identity a, Identity a) -> Identity a -> IntinRange :: (Identity a, Identity a) -> Identity a -> Bool Source #rangeSize :: (Identity a, Identity a) -> Int Source #unsafeRangeSize :: (Identity a, Identity a) -> Int (Ix a, Ix b) => Ix (a, b) Source # Since: 2.1 Instance detailsDefined in GHC.Arr Methodsrange :: ((a, b), (a, b)) -> [(a, b)] Source #index :: ((a, b), (a, b)) -> (a, b) -> Int Source #unsafeIndex :: ((a, b), (a, b)) -> (a, b) -> IntinRange :: ((a, b), (a, b)) -> (a, b) -> Bool Source #rangeSize :: ((a, b), (a, b)) -> Int Source #unsafeRangeSize :: ((a, b), (a, b)) -> Int Ix (Proxy s) Source # Since: 4.7.0.0 Instance detailsDefined in Data.Proxy Methodsrange :: (Proxy s, Proxy s) -> [Proxy s] Source #index :: (Proxy s, Proxy s) -> Proxy s -> Int Source #unsafeIndex :: (Proxy s, Proxy s) -> Proxy s -> IntinRange :: (Proxy s, Proxy s) -> Proxy s -> Bool Source #rangeSize :: (Proxy s, Proxy s) -> Int Source #unsafeRangeSize :: (Proxy s, Proxy s) -> Int (Ix a1, Ix a2, Ix a3) => Ix (a1, a2, a3) Source # Since: 2.1 Instance detailsDefined in GHC.Arr Methodsrange :: ((a1, a2, a3), (a1, a2, a3)) -> [(a1, a2, a3)] Source #index :: ((a1, a2, a3), (a1, a2, a3)) -> (a1, a2, a3) -> Int Source #unsafeIndex :: ((a1, a2, a3), (a1, a2, a3)) -> (a1, a2, a3) -> IntinRange :: ((a1, a2, a3), (a1, a2, a3)) -> (a1, a2, a3) -> Bool Source #rangeSize :: ((a1, a2, a3), (a1, a2, a3)) -> Int Source #unsafeRangeSize :: ((a1, a2, a3), (a1, a2, a3)) -> Int Ix a => Ix (Const a b) Source # Since: 4.9.0.0 Instance detailsDefined in Data.Functor.Const Methodsrange :: (Const a b, Const a b) -> [Const a b] Source #index :: (Const a b, Const a b) -> Const a b -> Int Source #unsafeIndex :: (Const a b, Const a b) -> Const a b -> IntinRange :: (Const a b, Const a b) -> Const a b -> Bool Source #rangeSize :: (Const a b, Const a b) -> Int Source #unsafeRangeSize :: (Const a b, Const a b) -> Int (Ix a1, Ix a2, Ix a3, Ix a4) => Ix (a1, a2, a3, a4) Source # Since: 2.1 Instance detailsDefined in GHC.Arr Methodsrange :: ((a1, a2, a3, a4), (a1, a2, a3, a4)) -> [(a1, a2, a3, a4)] Source #index :: ((a1, a2, a3, a4), (a1, a2, a3, a4)) -> (a1, a2, a3, a4) -> Int Source #unsafeIndex :: ((a1, a2, a3, a4), (a1, a2, a3, a4)) -> (a1, a2, a3, a4) -> IntinRange :: ((a1, a2, a3, a4), (a1, a2, a3, a4)) -> (a1, a2, a3, a4) -> Bool Source #rangeSize :: ((a1, a2, a3, a4), (a1, a2, a3, a4)) -> Int Source #unsafeRangeSize :: ((a1, a2, a3, a4), (a1, a2, a3, a4)) -> Int (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5) => Ix (a1, a2, a3, a4, a5) Source # Since: 2.1 Instance detailsDefined in GHC.Arr Methodsrange :: ((a1, a2, a3, a4, a5), (a1, a2, a3, a4, a5)) -> [(a1, a2, a3, a4, a5)] Source #index :: ((a1, a2, a3, a4, a5), (a1, a2, a3, a4, a5)) -> (a1, a2, a3, a4, a5) -> Int Source #unsafeIndex :: ((a1, a2, a3, a4, a5), (a1, a2, a3, a4, a5)) -> (a1, a2, a3, a4, a5) -> IntinRange :: ((a1, a2, a3, a4, a5), (a1, a2, a3, a4, a5)) -> (a1, a2, a3, a4, a5) -> Bool Source #rangeSize :: ((a1, a2, a3, a4, a5), (a1, a2, a3, a4, a5)) -> Int Source #unsafeRangeSize :: ((a1, a2, a3, a4, a5), (a1, a2, a3, a4, a5)) -> Int

# Deriving Instances of Ix

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.

• For an enumeration, the nullary constructors are assumed to be numbered left-to-right with the indices being 0 to n-1 inclusive. This is the same numbering defined by the Enum class. For example, given the datatype:
       data Colour = Red | Orange | Yellow | Green | Blue | Indigo | Violet

we would have:

       range   (Yellow,Blue)        ==  [Yellow,Green,Blue]
index   (Yellow,Blue) Green  ==  1
inRange (Yellow,Blue) Red    ==  False