Moving basic functions

Roman Cheplyaka roma at ro-che.info
Wed Apr 3 11:26:21 CEST 2013


* David Luposchainsky <dluposchainsky at googlemail.com> [2013-03-13 10:58:41+0100]
> Hello GHC HQ, hello mailing list,
> 
> there are a couple of basic functions that I think aren't where
> they should be.
> 
> 1. void is currently in Control.Monad. However, it is defined
>    only in terms of fmap (and therefore only has a Functor
>    constraint). Although this function is often used in a
>    monadic setting as ">> return ()", I really don't think
>    Control.Monad is the right place for it.

+1 for re-export

> 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.
> 
>       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.

-1, for the reasons already explained.

>    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.

-1. Note that swap x behaves exactly as x — you can use refutable or
irrefutable pattern matching on it and get the behaviour you desire.
Your swap' is more limited (you can't recover the strict behaviour), and 
really combines two unrelated things.

I'd +1 for Henning's forcePair if a better name is found (the word force
is normally associated with being strict, although I can see why he used
it here).

> 3. $>, a flipped version of <$, currently resides in
>    Control.Comonad, but should be in Data.Functor. Applicative
>    has <* and *>, Monad has >>= and =<<, and I personally keep
>    redefining (or specifically importing) $> quite often, and I
>    don't think I'm the only one.

+1

Roman



More information about the Libraries mailing list