Hello, people,
These are the comments and questions on
Haskell-98, .../~simonpj.../haskell98-final.txt:
------------------
Sergey Mechveliani
[EMAIL PROTECTED]
--------------------------------------------------------------------
*
Typo on the page 1:
Haskell 98 will be by no means be the last ...
~~
*
Typo: Chapter 4 ... `declatation'
*
FiniteMap
implemented via balanced binary trees.
Such a useful thing - has not it to move to the Standard library?
To my mind, it is more important for Haskell than arrays.
*
Question on standard Prelude, library definitions.
Standard Prelude, standard library define the values like
span, foldl, minimum, sort, and so on.
These definitions, they, probably, only specify what map has to be
computed. And the implementation is free to substitute any correct
definition. Right?
In particular, in Haskell-1.4, sort is defined via insert.
But this makes O(n^2) computational cost in the worst case.
While the merge sorting gives O( n*(log n) ). So the implementation
are, probably, encouraged to substitute merge sorting for sort - ?
And if the implementation does not do this, then the user can write
import Prelude hiding (sort ...)
(like, personally, i do) and re-define sort as one likes.
Does Haskell library presume all this, or maybe, i misunderstand
something?
Further, it was said long ago that the definition
foldl :: (a -> b -> a) -> a -> [b] -> a
foldl k z xs = f z xs
where
f z [] = z
f z (x:xs) = f (k z x) xs
is better than of the Haskell-1.4 Prelude - in the sense that in the
cases like sum [1..n] defined via foldl, the compilers recognise
the strictness more easy.
For the same reason, i define sum [] = 0
sum (x:xs) = x+(sum xs)
and "hide" the standard one. Similar are product, minimum, maximum.
Too much hiding. Have i to ask Haskell Prelude to improve, or rather
this is a proposal for implementation?
*
Some operations with association lists.
In Haskell-1.4 libraries i could not find a good replacement for
the following operations:
(have i missed something, or, is this improved in Haskell-98 ?)
removeFromAssocList :: Eq a => [(a,b)] -> a -> [(a,b)]
removeFromAssocList [] _ = []
removeFromAssocList ((x',y):pairs) x =
if
x==x' then pairs
else (x',y):(removeFromAssocList pairs x)
addToAssocList_C ::
Eq a => (b -> b -> b) -> [(a,b)] -> a -> b -> [(a,b)]
-- c
-- combines with the previous binding: when a key is
-- in the list, it binds with (c oldValue newValue)
addToAssocList_C c pairs key value = add pairs
where
add [] = [(key,value)]
add ((k,v):ps) = if k/=key then (k,v) :(add ps)
else (k, c v value) :ps
addListToAssocList_C ::
Eq a =>
(b -> b -> b) -> [(a,b)] -> [(a,b)] -> [(a,b)]
addListToAssocList_C c ps binds = foldl addOne ps binds
where
addOne ps (k,v) = addToAssocList_C c ps k v