Commit 8da89af8 authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Ix and a few typos

parent d82753bf
......@@ -216,6 +216,11 @@ Replace the definition of <tt>(!!)</tt> with the following:
(The original version had the property that <tt>([] !! -100)</tt>
reported "index too large".)
<p><li> [May 2000.] <strong>Page 132, Appendix D, Specification of Derived Instances</strong>.
In numbered item 3, replace
``(all constructors must by nullary)'' with
``(all constructors must be nullary)''.
<p><li> <strong>Page 141, Bibliograpy</strong>.
The library report citation [8] is out of date. It should read:
"Simon Peyton Jones and John Hughes (editors), Standard Libraries for the
......@@ -243,9 +248,54 @@ and that it does not claim to be a definition of the Haskell 98 libraries."
<p><li> <strong>Page 17, Section 5, first text line</strong>. Replace "continuous" by "contiguous".
<p><li> [May 2000] <strong>Page 17, Section 5, Indexing operations</strong>.
Add the following equation to the laws listed just before Section 5.1:
<pre>
map index (range (l,u)) == [0..rangeSize (l,u)]
</pre>
This documents an invariant that was previously only implicit.
<p><li> [May 2000] <strong>Page 17, Section 5, Indexing operations</strong>.
This significant item (a) removes <tt>Ord</tt> from <tt>Ix</tt>'s superclasses, and
(b) make <tt>rangeSize</tt> into a method of <tt>Ix</tt> rather than a free-standing declaration.
Though these changes are
visible to the programmer, all existing Haskell 98 programs will continue to work.
<ul>
<li> <strong>Page 17, Section 5, Indexing operations, boxed text</strong>. Replace the <tt>Ix</tt>
change the class declaration, and the type signature for <tt>rangeSize</tt> with:
<pre>
class Ix a where
range :: (a,a) -> [a]
index :: (a,a) -> a -> Int
inRange :: (a,a) -> a -> Bool
rangeSize :: (a,a) -> Int
</pre>
<li> <strong>Section 5.2, pages 19, line 3</strong>. Replace the <tt>Ix</tt>
class declaration, and the <tt>rangeSize</tt> declaration, with:
<pre>
class Ix a where
range :: (a,a) -> [a]
index :: (a,a) -> a -> Int
inRange :: (a,a) -> a -> Bool
rangeSize :: (a,a) -> Int
rangeSize b@(l,h) | null (range b) = 0
-- NB: replacing "null (range b)" by "not (l <= h)"
-- fails if the bounds are tuples. For example,
-- (1,2) <= (2,1)
-- but the range is nevertheless empty
-- range ((1,2),(2,1)) = []
</pre>
</ul>
<p><li> <strong>Page 22, Section 6.3; and Page 23, Fig 3</strong>:
Replace "<tt>map</tt>" by "<tt>fmap</tt>" (two occurrences in 6.3, one in Fig 3).
<p><li> [May 2000] <strong>Page 23, Figure 3</strong>.
In the definition of <tt>diag</tt>, delete the guard ``<tt>| l==l' &amp;&amp; u==u'</tt>''.
(The original intent was presumably to check for a square array, but
simply makes the definition recursive and hence divergent.)
<p><li> <strong>Page 29, Section 7.2</strong>. Add a new bullet for <tt>nub</tt>.
Add an index entry for <tt>nub</tt>.
......
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
class Ix a where
range :: (a,a) -> [a]
index :: (a,a) -> a -> Int
inRange :: (a,a) -> a -> Bool
rangeSize :: (a,a) -> Int
rangeSize :: Ix a => (a,a) -> Int
rangeSize b@(l,h) | null (range b) = 0
| otherwise = index b h + 1
rangeSize b@(l,h) | null (range b) = 0
| otherwise = index b h + 1
-- NB: replacing "null (range b)" by "l > h" fails if
-- the bounds are tuples. For example,
-- (2,1) > (1,2),
......
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 :: (Ix a) => (a,a) -> Int
class 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 ...
......
......@@ -20,9 +20,9 @@ An implementation is entitled to assume the following laws about these
operations:
\bprog
@
range (l,u) !! index (l,u) i == i -- when i is in range
inRange (l,u) i == i `elem` range (l,u)
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)]
@
\eprog
......
%
% $Header: /home/cvs/root/haskell-report/report/derived.verb,v 1.1 2001/03/28 14:13:42 simonpj Exp $
% $Header: /home/cvs/root/haskell-report/report/derived.verb,v 1.2 2001/05/28 14:39:47 simonpj Exp $
%
% The paragraph describing the formats of standard representations might
% be deleted, since the info is already in the Prelude.
......@@ -39,7 +39,7 @@ holds for each of the constituent types "t_{ij}".
\item
If "C" is @Bounded@, the type must be either an enumeration (all
constructors must by nullary) or have only one constructor.
constructors must be nullary) or have only one constructor.
\item
If "C" is @Enum@, the type must be an enumeration.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment