Moving basic functions
Henning Thielemann
lemming at henning-thielemann.de
Wed Mar 13 11:21:59 CET 2013
On Wed, 13 Mar 2013, David Luposchainsky wrote:
> 2. a) swap is the only function from Data.Tuple that is not
> exported to Prelude. On #haskell, people are sometimes
> even surprised there /is/ a Data.Tuple, and redefine
> their own version of swap at need. I therefore suggest
> including Data.Tuple.swap in the Prelude.
This means that Data.Tuple should contain more functions such that it
is used more than today! :-)
You may get inspirations from my own Data.Tuple module:
http://hackage.haskell.org/packages/archive/utility-ht/0.0.8/doc/html/Data-Tuple-HT.html
> The obvious downside of this change would of course be
> that it breaks code if there is a top-level user-defined
> version of it. Fixing this is of course trivial, but
> necessary.
Prelude is different from other modules since it is always imported
without qualification and without import list. That is, strictly speaking,
the Prelude must be in a separate package and you have to import it with
tight version bounds like Prelude >98.0.0 && <98.0.1 in order to adhere to
the package versioning policy. But actually, Prelude is part of the 'base'
package and people tend to specify no version bound at all.
Thus it is not only tedious work to update packages to a Prelude that
exports 'swap' but it becomes even more tedious to write a package that
works with old and new Prelude. - I think it would mean to import all
identifiers from Prelude explicitly.
For me, importing of Data.Tuple is the smaller problem and the more useful
functions it contains the more it pays off.
> b) A related suggestion would be the addition of an
> irrefutable swap, (swap'?), defined as
> "swap ~(a,b) = (b,a)", and its addition to Prelude for
> the same reasons.
An alternative to adding a lazy version of every function would be to add
a function like forcePair (forcePair ~(a,b) = (a,b)) that can be combined
with any pair function.
More information about the Libraries
mailing list