Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Haskell
prime
Commits
8da89af8
Commit
8da89af8
authored
May 28, 2001
by
Simon Peyton Jones
Browse files
Ix and a few typos
parent
d82753bf
Changes
5
Hide whitespace changes
Inline
Sidebyside
haskell98bugs.html
View file @
8da89af8
...
...
@@ 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 freestanding 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'
&&
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>
.
...
...
libraries/code/Ix.hs
View file @
8da89af8
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),
...
...
libraries/headers/Ix.hs
View file @
8da89af8
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
...
...
...
libraries/ix.verb
View file @
8da89af8
...
...
@@ 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..
range
Size
(l,u)
]
@
\eprog
...
...
report/derived.verb
View file @
8da89af8
%
% $Header: /home/cvs/root/haskellreport/report/derived.verb,v 1.
1
2001/0
3
/28 14:
1
3:4
2
simonpj Exp $
% $Header: /home/cvs/root/haskellreport/report/derived.verb,v 1.
2
2001/0
5
/28 14:3
9
:4
7
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 b
y
nullary) or have only one constructor.
constructors must b
e
nullary) or have only one constructor.
\item
If "C" is @Enum@, the type must be an enumeration.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment