Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Haskell
prime
Commits
79797dcf
Commit
79797dcf
authored
May 30, 2001
by
Simon Peyton Jones
Browse files
Small revision to May release (deriving, tuples)
parent
e524f97a
Changes
4
Hide whitespace changes
Inline
Side-by-side
haskell98-bugs.html
View file @
79797dcf
...
...
@@ -215,15 +215,14 @@ Replace the first paragraph of this section with:
"Tuples are algebraic datatypes with special syntax, as defined
in Section 3.8. Each tuple type has a single constructor.
All tuples are instances of
<tt>
Eq
</tt>
,
<tt>
Ord
</tt>
,
<tt>
Bounded
</tt>
,
<tt>
Read
</tt>
,
and
<tt>
Show
</tt>
(provided, of course, that all their component types are).
Classes defined in the libraries may also supply
instances for tuple types.
<tt>
Show
</tt>
, and
<tt>
Ix
</tt>
(provided, of course, that all their component types are).
<p>
There is no upper bound on the size of a tuple, but some Haskell
implementations may restrict the size of tuples, and limit the
instances associated with larger tuples. However, every Haskell
implementation must support tuples up to size 7, and their instances
for
<tt>
Eq
</tt>
,
<tt>
Ord
</tt>
,
<tt>
Bounded
</tt>
,
<tt>
Read
</tt>
, and
<tt>
Show
</tt>
. The Prelude and
for
<tt>
Eq
</tt>
,
<tt>
Ord
</tt>
,
<tt>
Bounded
</tt>
,
<tt>
Read
</tt>
,
<tt>
Show
</tt>
, and
<tt>
Ix
</tt>
. The Prelude and
libraries define tuple functions such as
<tt>
zip
</tt>
for tuples up to a size
of 7."
...
...
report/PreludeText.hs
View file @
79797dcf
...
...
@@ -128,10 +128,16 @@ lex (c:s) | isSingle c = [([c],s)]
lexExp
s
=
[(
""
,
s
)]
instance
Show
Int
where
showsPrec
=
showSigned
showInt
showsPrec
=
showsPrec
.
toInteger
-- Converting to Integer avoids
-- possible difficulty with minInt
instance
Read
Int
where
readsPrec
p
=
readSigned
readDec
readsPrec
p
r
=
(
fromInteger
i
,
t
)
where
(
i
,
t
)
=
readsPrec
p
r
-- Reading at the Integer type avoids
-- possible difficulty with minInt
instance
Show
Integer
where
showsPrec
=
showSigned
showInt
...
...
report/basic.verb
View file @
79797dcf
%
% $Header: /home/cvs/root/haskell-report/report/basic.verb,v 1.
3
2001/05/30 1
0:59:06
simonpj Exp $
% $Header: /home/cvs/root/haskell-report/report/basic.verb,v 1.
4
2001/05/30 1
3:47:12
simonpj Exp $
%
%**<title>The Haskell 98 Report: Basic Types and Classes</title>
%*section 6
...
...
@@ -116,15 +116,13 @@ respectively. Lists are an instance of classes @Read@, @Show@, @Eq@, @Ord@,
Tuples are algebraic datatypes with special syntax, as defined
in Section~\ref{tuples}. Each tuple type has a single constructor.
All tuples are instances of @Eq@, @Ord@, @Bounded@, @Read@,
and @Show@ (provided, of course, that all their component types are).
Classes defined in the libraries may also supply
instances for tuple types.
@Show@, and @Ix@ (provided, of course, that all their component types are).
There is no upper bound on the size of a tuple, but some \Haskell{}
implementations may restrict the size of tuples, and limit the
instances associated with larger tuples. However, every Haskell
implementation must support tuples up to size 7, and their instances
for @Eq@, @Ord@, @Bounded@, @Read@,
and
@Show@. The Prelude and
for @Eq@, @Ord@, @Bounded@, @Read@, @Show@
, and @Ix@
. The Prelude and
libraries define tuple functions such as @zip@ for tuples up to a size
of 7.
...
...
report/derived.verb
View file @
79797dcf
%
% $Header: /home/cvs/root/haskell-report/report/derived.verb,v 1.
3
2001/05/
29
1
5
:4
0:00
simonpj Exp $
% $Header: /home/cvs/root/haskell-report/report/derived.verb,v 1.
4
2001/05/
30
1
3
:4
7:12
simonpj Exp $
%
% The paragraph describing the formats of standard representations might
% be deleted, since the info is already in the Prelude.
...
...
@@ -373,25 +373,25 @@ formatting of floating point numbers.
%@@
%readList:: ReadS [a]
%readList r = [pr | ("[",s) <- lex r,
%
pr
<- readl s
]
%
where readl s = [([],t) | ("]",t) <- lex s] ++
%
[(x:xs,v) |
(x,t) <- reads s,
%
(",",u) <- lex t,
%
(xs,v) <- readl u
]
%
pr
<- readl s
]
%
where readl s = [([],t) | ("]",t) <- lex s] ++
%
[(x:xs,v) |
(x,t) <- reads s,
%
(",",u) <- lex t,
%
(xs,v) <- readl u
]
%
%showList:: [a] -> ShowS
%showList xs = showChar '[' . showl xs
%
where
%
showl [] = showChar ']'
%
showl (x:xs) = shows x . showChar ',' . showl xs
%
where
%
showl [] = showChar ']'
%
showl (x:xs) = shows x . showChar ',' . showl xs
%@@
%\eprog
%\begin{figure}
%\outline{
%@@
%instance (C, Text u1, ..., Text uk) => Text (T u1 ... uk) where
%
showsPrec = ...
%
readsPrec = ...
%
showsPrec = ...
%
readsPrec = ...
%@@
%}
%\caption{General form of a derived instance of @Text@}
...
...
@@ -430,44 +430,44 @@ the class declaration shown in Figure~\ref{standard-classes}
\begin{figure}[tb]
\outlinec{
@
infix
4
:^:
infix
5
:^:
data Tree a = Leaf a | Tree a :^: Tree a
instance (Eq a) => Eq (Tree a) where
Leaf m == Leaf n = m==n
u:^:v == x:^:y
= u==x && v==y
Leaf m == Leaf n = m==n
u:^:v == x:^:y
= u==x && v==y
_ == _ = False
instance (Ord a) => Ord (Tree a) where
Leaf m <= Leaf n = m<=n
Leaf m <= x:^:y
= True
u:^:v <= Leaf n = False
u:^:v <= x:^:y
= u<x || u==x && v<=y
Leaf m <= Leaf n = m<=n
Leaf m <= x:^:y
= True
u:^:v <= Leaf n = False
u:^:v <= x:^:y
= u<x || u==x && v<=y
instance (Show a) => Show (Tree a) where
showsPrec d (Leaf m) = showParen (d >= 10) showStr
where
where
showStr = showString "Leaf " . showsPrec 10 m
showsPrec d (u :^: v) = showParen (d > 4) showStr
where
where
showStr = showsPrec 5 u .
showString " :^: " .
showsPrec 5 v
instance (Read a) => Read (Tree a) where
readsPrec d r = readParen (d > 4)
(\r -> [(u:^:v,w) |
(u,s) <- readsPrec 5 r,
(":^:",t) <- lex s,
(v,w) <- readsPrec 5 t]) r
readsPrec d r = readParen (d > 4)
(\r -> [(u:^:v,w) |
(u,s) <- readsPrec 5 r,
(":^:",t) <- lex s,
(v,w) <- readsPrec 5 t]) r
++ readParen (d > 9)
(\r -> [(Leaf m,t) |
("Leaf",s) <- lex r,
(m,t) <- readsPrec 10 s]) r
++ readParen (d > 9)
(\r -> [(Leaf m,t) |
("Leaf",s) <- lex r,
(m,t) <- readsPrec 10 s]) r
@
}
%**<div align=center> <h4>Figure 8</h4> </div>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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