Commit 78452ce9 authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Small matters

parent fdb67ba2
......@@ -242,6 +242,15 @@ with the following:
</pre>
(The previous example use boolean and, which is non-strict in its second argument!)
<p><li> [Jan 2002] <strong>Page 31, Section 3.17.2, Informal Semantics of Case Expressions.</strong>
Reword the entire numbered list giving the informal semantics, so that:
<ul>
<li> It is clearly classified by pattern.
<li> The semantics of matching a newtype pattern against bottom is given.
<li> A literal and n+k pattern may not diverge even if the value matched is bottom; it
depends on the definition of <tt>==</tt> and <tt>&gt;=</tt> respectively.
</ul>
<p><li> [Apr 2001] <strong>Page 31,33, Figures 3 and 4, Semantics of Case Expressions.</strong>
Replace "completely new variable" by "new variable" in these two figures. (Some clauses
said "new" and some "completely new" which is misleadingly inconsistent.)
......@@ -249,6 +258,20 @@ said "new" and some "completely new" which is misleadingly inconsistent.)
<p><li> [Apr 2001] <strong>Page 33, Figure 4, Semantics of Case Expressions Part 2.</strong>
In clause (r) replace "e0" by "v" throughout.
<p><li> [Jan 2002] <strong>Page 33, Figure 4, Semantics of Case Expressions Part 2.</strong>
<ul>
<li> Insert new clause (r):
<pre>
case _|_ of { K x1 ... xn -> e; _ -> e' } = _|_
where K is a data constructor of arity n
</pre>
<li> Rename old clause (r) as clause (s).
<li> Use lambda instead of let in the new clause (s), so as to avoid the suggestion
of polymorphism (just as in other clauses.
<li> In the accompanying text, final paragaph, add clause (s) to the list of
clauses that use lambda to avoid suggesting polymorphism.
</ul>
<p><li> [Sept 2001] <strong>Page 36, Section 4.1.2, Syntax of Types.</strong>
First paragraph, last sentence. After "infix type constructors are not allowed",
add "(other than <tt>(->)</tt>)".
......@@ -841,6 +864,10 @@ Replace the definitions of <tt>take</tt>, <tt>drop</tt>, and <tt>splitAt</tt> wi
The effect is that all three functions are defined on negative arguments. This
is a semantic change.
<p><li> [Jan 2002] <strong>Page 113, header for PreludeText</strong>.
Remove <tt>show</tt> from the export list, and re-insert it as an exported
operation of class <tt>Show</tt>.
<p><li> [Nov 2001] <strong>Page 114, definition of lex</strong>.
Change the line that currently reads
<pre>
......@@ -1253,6 +1280,10 @@ consistent with the other "By" functions, and with the signatures given on page
<p><li> [Dec 2001] <strong>Page 41, Sections 9, Character utilities</strong>.
Add an explanation of <tt>lexLitChar</tt>, and an example.
<p><li> [Jan 2002] <strong>Page 43, Sections 9.1, Character utilities</strong>.
Add <tt>isLatin1</tt> to the list of variables in the type signature
for "character-testing operations".
<p><li><strong>Page 48, Sections 10.3, Monads</strong>.
In the definition of <tt>listFile</tt> replace "<tt>openFile</tt>" by "<tt>readFile</tt>".
......
......@@ -15,7 +15,7 @@ import Numeric (readDec, readOct, lexDigits, readHex)
import UnicodePrims -- Source of primitive Unicode functions.
-- Character-testing operations
isAscii, isControl, isPrint, isSpace, isUpper, isLower,
isAscii, isLatin1, isControl, isPrint, isSpace, isUpper, isLower,
isAlpha, isDigit, isOctDigit, isHexDigit, isAlphaNum :: Char -> Bool
isAscii c = c < '\x80'
......
......@@ -10,8 +10,8 @@ module Prelude (
-- are denoted by built-in syntax, and cannot legally
-- appear in an export list.
-- List type: []((:), [])
-- Tuple types: (,), (,,), etc.
-- Trivial type: ()
-- Tuple types: (,)((,)), (,,)((,,)), etc.
-- Trivial type: ()(())
-- Functions: (->)
Eq((==), (/=)),
......
module PreludeText (
ReadS, ShowS,
Read(readsPrec, readList),
Show(showsPrec, showList),
reads, shows, show, read, lex,
Show(showsPrec, show, showList),
reads, shows, read, lex,
showChar, showString, readParen, showParen ) where
-- The instances of Read and Show for
......
%
% $Header: /home/cvs/root/haskell-report/report/derived.verb,v 1.7 2001/11/02 16:26:48 simonpj Exp $
% $Header: /home/cvs/root/haskell-report/report/derived.verb,v 1.8 2002/01/29 09:46:41 simonpj Exp $
%
% The paragraph describing the formats of standard representations might
% be deleted, since the info is already in the Prelude.
......@@ -117,11 +117,12 @@ through "u_k".
%% @@
%% \eprog
When inferring the context for the derived instances, type synonyms
must be expanded out first.\index{type synonym}
Free names in the declarations $d$ are all
defined in the Prelude; the qualifier `@Prelude.@' is
implicit here. The remaining details of the derived
in the constructors' argument types must be expanded out first.\index{type synonym}
The remaining details of the derived
instances for each of the derivable Prelude classes are now given.
Free variables and constructors used in these translations
always refer to entities defined by the @Prelude@.
\subsection{Derived instances of @Eq@ and @Ord@.}
\indexdi{Eq}
......
%
% $Header: /home/cvs/root/haskell-report/report/exps.verb,v 1.14 2001/12/21 16:00:24 simonpj Exp $
% $Header: /home/cvs/root/haskell-report/report/exps.verb,v 1.15 2002/01/29 09:46:41 simonpj Exp $
%
%*section 3
%**<title>The Haskell 98 Report: Expressions</title>
......@@ -193,6 +193,7 @@ only suggestions; implementations may choose to display more or less
information when an error occurs.
\subsection{Variables, Constructors, Operators, and Literals}
\label{vars-and-lits}
%
@@@
aexp -> qvar & (\tr{variable})
......@@ -1198,24 +1199,15 @@ succeed}, returning a binding for each variable in the pattern; or it
may {\em diverge} (i.e.~return "\bot"). Pattern matching proceeds
from left to right, and outside to inside, according to the following rules:
\begin{enumerate}
\item Matching a value "v" against the irrefutable pattern
\index{irrefutable pattern}
"var" always succeeds and binds "var" to "v".
Similarly, matching "v" against the irrefutable pattern "@~@apat" always succeeds.
The free
variables in "apat" are bound to the appropriate values if matching
"v" against "apat" would otherwise succeed, and to "\bot" if matching
"v" against "apat" fails or diverges. (Binding does {\em
not} imply evaluation.)
Matching any value against the wildcard pattern @_@ always succeeds
and no binding is done.
\item Matching the pattern "var"
against a value "v" always succeeds and binds "var" to "v".
% Matching a value "con v" against the pattern "con apat" where "con" is an
% abstract datatype constructor and "apat" is irrefutable always succeeds
% and binds "var" to "v". Matching "\bot" against the pattern "con apat" where
% "con" is an abstract datatype constructor and "apat" is irrefutable always
% succeeds and matches "\bot" to "apat".
\item
Matching the pattern "@~@apat" against a value "v" always succeeds.
The free variables in "apat" are bound to the appropriate values if matching
"apat" against "v" would otherwise succeed, and to "\bot" if matching
"apat" against "v" fails or diverges. (Binding does {\em
not} imply evaluation.)
Operationally, this means that no matching is done on an
irrefutable pattern until one of the variables in the pattern is used.
......@@ -1223,45 +1215,54 @@ At that point the entire pattern is matched against the value, and if
the match fails or diverges, so does the overall computation.
\item
Matching a value "con v" against the pattern "con pat", where "con" is a
constructor defined by @newtype@, is equivalent to matching "v"
against the pattern "pat". That is, constructors associated with
@newtype@ serve only to change the type of a value.\index{newtype declaration@@{\tt newtype} declaration}
Matching the wildcard pattern @_@ agains any value always succeeds,
and no binding is done.
\item Matching "\bot" against a refutable pattern always diverges.
\index{refutable pattern}
\item
Matching the pattern "con pat" against a value, where "con" is a
constructor defined by @newtype@, depends on the value:
\begin{itemize}
\item If the value is of the form "con v", the result is result of matching "pat" against "v".
\item If the value is "\bot", the result is the result of matching "pat" against "\bot".
\end{itemize}
That is, constructors associated with
@newtype@ serve only to change the type of a value.\index{newtype declaration@@{\tt newtype} declaration}
\item Matching a non-"\bot" value can occur against three kinds of
refutable patterns:
\begin{enumerate}
\item Matching a non-"\bot" value against a pattern whose outermost
component is a constructor defined by @data@
\index{constructed pattern}
fails if the value being matched was created by a
different constructor. If the constructors are
the same, the result of the match is the result of matching the
sub-patterns left-to-right against the components of the data value:
\item
Matching the pattern "con pat_1 \ldots pat_n" against a value, where "con" is a
constructor defined by @data@, depends on the value:
\begin{itemize}
\item If the value is of the form "con v_1 \ldots v_n",
the result of the match is the result of matching the
sub-patterns left-to-right against the components of the data value;
if all matches succeed, the overall match
succeeds; the first to fail or diverge causes the overall match to
fail or diverge, respectively.
%Also, literals (characters, positive and
%negative integers, and the unit value @()@) are treated as nullary
%constructors.
\item Numeric literals are matched using the overloaded @==@ function.
The behavior of numeric patterns depends entirely on the definition of
@==@ and @fromInteger@ (integer literals) or @fromRational@ (floating point literals)
for the type of object being matched.
\item If the value is of the form "con' v_1 \ldots v_m", where "con" is a different
constructor to "con'", the match fails.
\item If the value is "\bot", the match diverges.
\end{itemize}
\item Matching a non-"\bot" value "x" against a pattern of the form
"n@+@k"
\item Matching a numeric integer literal pattern "k" against a value "v"
\index{literal pattern}
succeeds if "v ~@==@ ~(@fromInteger@~k)", where both @==@ and @fromInteger@
are overloaded based on the type of the pattern. The match diverges if
this test diverges.
Matching a floating-point literal is similar, except that @fromRational@ is used,
as in the case of literals in expressions (Section~\ref{vars-and-lits}).
\item Matching an "n@+@k" pattern (where "n" is a variable and "k" is a
positive integer literal) against a value "v"
\index{n+k pattern@@"n@+@k" pattern}
(where "n" is a variable and "k" is a positive integer
literal) succeeds if "x>=k", resulting in the binding of "n" to "x-k",
and fails if "x<k". The behavior of "n@+@k" patterns depends entirely
on the underlying definitions of @>=@, @fromInteger@, and @-@ for the
type of the object being matched.
\end{enumerate}
succeeds if "x ~@>=@ ~(@fromInteger@ k)", resulting in the binding
of "n" to "x~@-@~(@fromInteger@~k)",
and fails otherwise. Again, the functions @>=@, @fromInteger@, and @-@, are all
overloaded, depending on the type of the pattern.
The match diverges if the comparison diverges.
\item
Matching against a constructor using labeled fields is the same as
......@@ -1272,10 +1273,10 @@ more than once. Fields not named by the pattern are ignored (matched
against @_@).
\item
The result of matching a value "v" against an as-pattern "var"{\tt @@}"apat" is
Matching an as-pattern "var"{\tt @@}"apat" against a value "v" is
\index{as-pattern ({\tt {\char'100}})}
the result of matching "v" against "apat" augmented with the binding of
"var" to "v". If the match of "v" against "apat" fails or diverges,
the result of matching "apat" against "v", augmented with the binding of
"var" to "v". If the match of "apat" against "v" fails or diverges,
then so does the overall match.
\end{enumerate}
......@@ -1492,11 +1493,12 @@ $e'$ @ }@ \\
(q)&@case (@$K$@ @$e_1$@ @$\ldots$@ @$e_n$@) of { @$K$@ @$x_1$@ @$\ldots$@ @$x_n$@ -> @$e$@; _ -> @$e'$@ }@\\
&$=$@ case @$e_1$@ of { @$x'_1$@ -> @$\ldots$@ case @$e_n$@ of { @$x'_n$@ -> @$e[x'_1/x_1 \ldots x'_n/x_n]$@ }@$\ldots$@}@\\
&{\rm where $K$ is a constructor of arity $n$; $x'_1 \ldots x'_n$ are new variables}\\[4pt]
%(l)&@case (@$A$@ @$ e_1$@) of {@$A$@ @$ x_1$@ -> @$e$@; _ -> @$e'$@ }@\\
%&$=$@ case @$e1$@ of { @$x_1$@ -> @$e$@ }@\\
%&{\rm where $A$ is constructor defined by @newtype@}\\
(r)&@case @$v$@ of { @$x$@+@$k$@ -> @$e$@; _ -> @$e'$@ }@\\
&$=$@ if @$v$@ >= @$k$@ then let {@$x'$@ = @$v$@-@$k$@} in @$e[x'/x]$@ else @$e'$\\
(r)&@case@~$\bot$~@of { @$K$@ @$x_1$@ @$\ldots$@ @$x_n$@ -> @$e$@; _ -> @$e'$@ }@ ~$=$~ $\bot$ \\
&{\rm where $K$ is a constructor of arity $n$; $x'_1 \ldots x'_n$ are new variables}\\[4pt]
(s)&@case @$v$@ of { @$x$@+@$k$@ -> @$e$@; _ -> @$e'$@ }@\\
&$=$@ if @$v$@ >= @$k$@ then @(\$x'$@ -> @$e[x'/x]$)~($v$@-@$k$)@ else @$e'$\\
&{\rm where $k$ is a numeric literal, and $x'$ is a new variable}\\
\end{tabular}
}
......@@ -1545,7 +1547,7 @@ meaning of pattern matching against overloaded constants.
%% expressions, but doing so
%% would clutter the identities, which are intended only to convey the semantics.
These identities all preserve the static semantics. Rules~(d),~(e), and~(j)
These identities all preserve the static semantics. Rules~(d),~(e), (j), and~(s)
use a lambda rather than a @let@; this indicates that variables bound
by @case@ are monomorphically typed (Section~\ref{type-semantics}).
\index{monomorphic type variable}
......
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