Commit f9e974ec authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

More towards the revised report

parent 91ee8e76
......@@ -59,6 +59,8 @@ with "<tt>Int</tt>".
<p><li> [Apr 2001] <strong>Page 21, Section 3.11, List Comprehensions; and Page 128.</strong>
<ul> <li> In the production for "aexp", change the "n >= 0" to "n >= 1".
<li> Remove the production for (empty qualifier)
<li> In the translation box lower down the page, rewrite the translation so
that it does not involve and empty list of qualifiers. (Unchanged semantics.)
</ul>
This change ensures that there is at least one qualifier in list comprehension,
and no qualifier is empty. The translation lower down page 23 is then
......@@ -362,9 +364,7 @@ Replace the instances for <tt>Show Int</tt> and <tt>Read Int</tt> with
-- possible difficulty with minInt
instance Read Int where
readsPrec p r = (fromInteger i, t)
where
(i,t) = readsPrec p r
readsPrec p r = [(fromInteger i, t) | (i,t) <- readsPrec p r]
-- Reading at the Integer type avoids
-- possible difficulty with minInt
</pre>
......@@ -451,6 +451,7 @@ class declaration, and the <tt>rangeSize</tt> declaration, with:
rangeSize :: (a,a) -> Int
rangeSize b@(l,h) | null (range b) = 0
| otherwise = index b h + 1
-- NB: replacing "null (range b)" by "not (l <= h)"
-- fails if the bounds are tuples. For example,
-- (1,2) <= (2,1)
......@@ -460,6 +461,17 @@ class declaration, and the <tt>rangeSize</tt> declaration, with:
(Note: the comment has changed too; it was misleading before.)
</ul>
<p><li> [May 2001] <strong>Page 24, Section 6.6</strong>.
Add <tt>Eq a</tt> to the context for <tt>instance Eq (Array a b)</tt>, thus:
<pre>
instance (Ix a, Eq a, Eq b) => Eq (Array a b) ...
</pre>
Similarly, add <tt>Ord a</tt> to the context for <tt>instance Ord (Array a b)</tt>, thus:
<pre>
instance (Ix a, Ord a, Ord b) => Ord (Array a b) ...
</pre>
(Both consequences of removing <tt>Ord</tt> as a superclass of <tt>Ix</tt>.)
<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).
......@@ -474,6 +486,31 @@ Add an index entry for <tt>nub</tt>.
<p><li> <strong>Page 29, Section 7.2, second bullet</strong>.
Introduce a new bullet just before "<tt>union</tt> is list union".
<p><li> [May 2001] <strong>Page 30, Section 7.4, unfoldr</strong>.
Replace the first line-and-a-half paragraph with:
<p>
"The <tt>unfoldr</tt> function is a `dual' to <tt>foldr</tt>: while <tt>foldr</tt> reduces a list
to a summary value, <tt>unfoldr</tt> builds a list from a seed value. For
example:
<pre>
iterate f == unfoldr (\x -> Just (x, f x))
</pre>
In some cases, <tt>unfoldr</tt> can undo a <tt>foldr</tt> operation:"
<p>
(Followed by the existing displayed equation.)
<p><li> [May 2001] <strong>Page 32, Section 7.8, Library List</strong>.
<ul> <li> Add <tt>deleteFirstsBy</tt> to the export list. (It has always
been in the library, but the report failed to export it!)
<li> Generalise the type signatures of <tt>deleteBy</tt> and <tt>deleteFirstsBy</tt> to:
<pre>
deleteBy :: (x -> a -> Bool) -> x -> [a] -> [a]
deleteFirstsBy :: (x -> a -> Bool) -> [a] -> [x] -> [a]
</pre>
The definitions have these more general types, and they are occasionally useful.
</ul>
<p><li> [Apr 2001] <strong>Page 34, Section 7.8, Library List</strong>.
Replace the definition of <tt>partition</tt> by
<pre>
......
......@@ -60,11 +60,11 @@ ixmap b f a = array b [(i, a ! f i) | i <- range b]
instance (Ix a) => Functor (Array a) where
fmap fn (MkArray b f) = MkArray b (fn . f)
instance (Ix a, Eq b) => Eq (Array a b) where
a == a' = assocs a == assocs a'
instance (Ix a, Eq a, Eq b) => Eq (Array a b) where
a == a' = assocs a == assocs a'
instance (Ix a, Ord b) => Ord (Array a b) where
a <= a' = assocs a <= assocs a'
instance (Ix a, Ord a, Ord b) => Ord (Array a b) where
a <= a' = assocs a <= assocs a'
instance (Ix a, Show a, Show b) => Show (Array a b) where
showsPrec p a = showParen (p > 9) (
......
module List (
elemIndex, elemIndices,
find, findIndex, findIndices,
nub, nubBy, delete, deleteBy, (\\),
nub, nubBy, delete, deleteBy, (\\), deleteFirstsBy,
union, unionBy, intersect, intersectBy,
intersperse, transpose, partition, group, groupBy,
inits, tails, isPrefixOf, isSuffixOf,
......@@ -55,14 +55,14 @@ nubBy eq (x:xs) = x : nubBy eq (filter (\y -> not (eq x y)) xs)
delete :: Eq a => a -> [a] -> [a]
delete = deleteBy (==)
deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]
deleteBy :: (x -> a -> Bool) -> x -> [a] -> [a]
deleteBy eq x [] = []
deleteBy eq x (y:ys) = if x `eq` y then ys else y : deleteBy eq x ys
(\\) :: Eq a => [a] -> [a] -> [a]
(\\) = foldl (flip delete)
deleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
deleteFirstsBy :: (x -> a -> Bool) -> [a] -> [x] -> [a]
deleteFirstsBy eq = foldl (flip (deleteBy eq))
union :: Eq a => [a] -> [a] -> [a]
......
<title> The Haskell Library Report 1.4 </title>
<title> The Haskell 98 Library Report </title>
<body bgcolor="#ffffff">
......
......@@ -153,8 +153,15 @@ is processed from right-to-left rather than left-to-right.
\subsection{@unfoldr@}
The @unfoldr@\indextt{unfoldr} function undoes a @foldr@ operation. Note that,
in general, only invertible functions can be unfolded.
The @unfoldr@ function is a `dual' to @foldr@: while @foldr@ reduces a list
to a summary value, @unfoldr@ builds a list from a seed value. For
example:
\bprog
@
iterate f == unfoldr (\x -> Just (x, f x))
@
\eprog
In some cases, @unfoldr@ can undo a @foldr@ operation:
\bprog
@
unfoldr f' (foldr f z xs) == xs
......
......@@ -133,9 +133,7 @@ instance Show Int where
-- possible difficulty with minInt
instance Read Int where
readsPrec p r = (fromInteger i, t)
where
(i,t) = readsPrec p r
readsPrec p r = [(fromInteger i, t) | (i,t) <- readsPrec p r]
-- Reading at the Integer type avoids
-- possible difficulty with minInt
......
<title>The Haskell 98 Report</title>
<title>The Haskell 98 Language Report</title>
<body background="lambda.gif">
<hr>
<div align=center>
......
%
% $Header: /home/cvs/root/haskell-report/report/literate.verb,v 1.1 2001/03/28 14:13:42 simonpj Exp $
% $Header: /home/cvs/root/haskell-report/report/literate.verb,v 1.2 2001/06/11 13:10:05 simonpj Exp $
%
%**<title>The Haskell 98 Report: Literate Comments</title>
%*section C
......@@ -32,8 +32,8 @@ extension, with ``@.hs@'' indicating a usual Haskell file and
simple factorial program would be:
\bprog
@
> -- This literate program prompts the user for a number
> -- and prints the factorial of that number:
This literate program prompts the user for a number
and prints the factorial of that number:
> main :: IO ()
......@@ -42,7 +42,7 @@ simple factorial program would be:
> putStr "n!= "
> print (fact (read l))
This is the factorial function.
This is the factorial function.
> fact :: Integer -> Integer
> fact 0 = 1
......
Supports Markdown
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