<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Data.Ix</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[ window.onload = function () {pageLoad();setSynopsis("mini_Data-Ix.html");}; //]]> </script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">base-4.3.1.0: Basic libraries</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>portable</td></tr><tr><th>Stability</th><td>stable</td></tr><tr><th>Maintainer</th><td>libraries@haskell.org</td></tr></table><p class="caption">Data.Ix</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">The <code><a href="Data-Ix.html#t:Ix">Ix</a></code> class </a></li><li><a href="#g:2">Deriving Instances of <code><a href="Data-Ix.html#t:Ix">Ix</a></code> </a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>The <code><a href="Data-Ix.html#t:Ix">Ix</a></code> 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). </p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><span class="keyword">class</span> <a href="Data-Ord.html#t:Ord">Ord</a> a => <a href="#t:Ix">Ix</a> a <span class="keyword">where</span><ul class="subs"><li><a href="#v:range">range</a> :: (a, a) -> [a]</li><li><a href="#v:index">index</a> :: (a, a) -> a -> <a href="Data-Int.html#t:Int">Int</a></li><li><a href="#v:inRange">inRange</a> :: (a, a) -> a -> <a href="Data-Bool.html#t:Bool">Bool</a></li><li><a href="#v:rangeSize">rangeSize</a> :: (a, a) -> <a href="Data-Int.html#t:Int">Int</a></li></ul></li></ul></div><div id="interface"><h1 id="g:1">The <code><a href="Data-Ix.html#t:Ix">Ix</a></code> class </h1><div class="top"><p class="src"><span class="keyword">class</span> <a href="Data-Ord.html#t:Ord">Ord</a> a => <a name="t:Ix" class="def">Ix</a> a <span class="keyword">where</span></p><div class="doc"><p>The <code><a href="Data-Ix.html#t:Ix">Ix</a></code> 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). </p><p>The first argument <code>(l,u)</code> of each of these operations is a pair specifying the lower and upper bounds of a contiguous subrange of values. </p><p>An implementation is entitled to assume the following laws about these operations: </p><ul><li> <code><code><a href="Data-Ix.html#v:inRange">inRange</a></code> (l,u) i == <code><a href="Data-List.html#v:elem">elem</a></code> i (<code><a href="Data-Ix.html#v:range">range</a></code> (l,u))</code> <code> </code> </li><li> <code><code><a href="Data-Ix.html#v:range">range</a></code> (l,u) <code><a href="Data-List.html#v:-33--33-">!!</a></code> <code><a href="Data-Ix.html#v:index">index</a></code> (l,u) i == i</code>, when <code><code><a href="Data-Ix.html#v:inRange">inRange</a></code> (l,u) i</code> </li><li> <code><code><a href="Data-List.html#v:map">map</a></code> (<code><a href="Data-Ix.html#v:index">index</a></code> (l,u)) (<code><a href="Data-Ix.html#v:range">range</a></code> (l,u))) == [0..<code><a href="Data-Ix.html#v:rangeSize">rangeSize</a></code> (l,u)-1]</code> <code> </code> </li><li> <code><code><a href="Data-Ix.html#v:rangeSize">rangeSize</a></code> (l,u) == <code><a href="Data-List.html#v:length">length</a></code> (<code><a href="Data-Ix.html#v:range">range</a></code> (l,u))</code> <code> </code> </li></ul><p>Minimal complete instance: <code><a href="Data-Ix.html#v:range">range</a></code>, <code><a href="Data-Ix.html#v:index">index</a></code> and <code><a href="Data-Ix.html#v:inRange">inRange</a></code>. </p></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a name="v:range" class="def">range</a> :: (a, a) -> [a]</p><div class="doc"><p>The list of values in the subrange defined by a bounding pair. </p></div><p class="src"><a name="v:index" class="def">index</a> :: (a, a) -> a -> <a href="Data-Int.html#t:Int">Int</a></p><div class="doc"><p>The position of a subscript in the subrange. </p></div><p class="src"><a name="v:inRange" class="def">inRange</a> :: (a, a) -> a -> <a href="Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>Returns <code><a href="Data-Bool.html#v:True">True</a></code> the given subscript lies in the range defined the bounding pair. </p></div><p class="src"><a name="v:rangeSize" class="def">rangeSize</a> :: (a, a) -> <a href="Data-Int.html#t:Int">Int</a></p><div class="doc"><p>The size of the subrange defined by a bounding pair. </p></div></div><div class="subs instances"><p id="control.i:Ix" class="caption collapser" onclick="toggleSection('i:Ix')">Instances</p><div id="section.i:Ix" class="show"><table><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="Data-Bool.html#t:Bool">Bool</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="Data-Char.html#t:Char">Char</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="Data-Int.html#t:Int">Int</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="Data-Int.html#t:Int8">Int8</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="Data-Int.html#t:Int16">Int16</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="Data-Int.html#t:Int32">Int32</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="Data-Int.html#t:Int64">Int64</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="Prelude.html#t:Integer">Integer</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="Data-Ord.html#t:Ordering">Ordering</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="Data-Word.html#t:Word">Word</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="Data-Word.html#t:Word8">Word8</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="Data-Word.html#t:Word16">Word16</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="Data-Word.html#t:Word32">Word32</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="Data-Word.html#t:Word64">Word64</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> ()</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="System-IO.html#t:IOMode">IOMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="GHC-IO-Device.html#t:SeekMode">SeekMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="Data-Char.html#t:GeneralCategory">GeneralCategory</a></td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="Data-Ix.html#t:Ix">Ix</a> a, <a href="Data-Ix.html#t:Ix">Ix</a> b) => <a href="Data-Ix.html#t:Ix">Ix</a> (a, b)</td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="Data-Ix.html#t:Ix">Ix</a> a1, <a href="Data-Ix.html#t:Ix">Ix</a> a2, <a href="Data-Ix.html#t:Ix">Ix</a> a3) => <a href="Data-Ix.html#t:Ix">Ix</a> (a1, a2, a3)</td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="Data-Ix.html#t:Ix">Ix</a> a1, <a href="Data-Ix.html#t:Ix">Ix</a> a2, <a href="Data-Ix.html#t:Ix">Ix</a> a3, <a href="Data-Ix.html#t:Ix">Ix</a> a4) => <a href="Data-Ix.html#t:Ix">Ix</a> (a1, a2, a3, a4)</td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="Data-Ix.html#t:Ix">Ix</a> a1, <a href="Data-Ix.html#t:Ix">Ix</a> a2, <a href="Data-Ix.html#t:Ix">Ix</a> a3, <a href="Data-Ix.html#t:Ix">Ix</a> a4, <a href="Data-Ix.html#t:Ix">Ix</a> a5) => <a href="Data-Ix.html#t:Ix">Ix</a> (a1, a2, a3, a4, a5)</td><td class="doc empty"> </td></tr></table></div></div></div><h1 id="g:2">Deriving Instances of <code><a href="Data-Ix.html#t:Ix">Ix</a></code> </h1><div class="doc"><p>Derived instance declarations for the class <code><a href="Data-Ix.html#t:Ix">Ix</a></code> 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 <code><a href="Data-Ix.html#t:Ix">Ix</a></code>. </p><ul><li> 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 <code>Enum</code> class. For example, given the datatype: </li></ul><pre> data Colour = Red | Orange | Yellow | Green | Blue | Indigo | Violet </pre><p>we would have: </p><pre> range (Yellow,Blue) == [Yellow,Green,Blue] index (Yellow,Blue) Green == 1 inRange (Yellow,Blue) Red == False </pre><ul><li> For single-constructor datatypes, the derived instance declarations are as shown for tuples in Figure 1 <a href="http://www.haskell.org/onlinelibrary/ix.html#prelude-index">http://www.haskell.org/onlinelibrary/ix.html#prelude-index</a>. </li></ul></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.9.2</p></div></body></html>