On on (was: [GHC] #971: Add intercalate and split to Data.List)
Jon Fairbairn
jon.fairbairn at cl.cam.ac.uk
Thu Nov 2 11:24:08 EST 2006
On 2006-11-02 at 15:28+0100 Nils Anders Danielsson wrote:
> On Mon, 30 Oct 2006, Jón Fairbairn <jon.fairbairn at cl.cam.ac.uk> wrote:
>
> > We can write “groupBy (\a b -> p a && p b)” [...]
>
> You mean “groupBy ((&&) `on` p)”, right? ;)
Something very much like that!
> Do you consider on to be above or below the Fairbairn threshold, by
> the way?
Above. It's hard to articulate, but the reasons you give for
`on` seem about right, so long as on is defined at a general
enough type (and it's hard to beat forall a b c. (a -> a ->
b) -> (c -> a) -> c -> t -> b for generality!)
To explore this a bit further with a different example, I
would have been in favour of introducing
(f >< g) (a, b) = (f a, f b)
but not
mapFst f (a, b) = (f a, b)
because the latter is simply (f >< id), which has a nice
"parallel" look to it; it seems easier to me to see that
(f >< id) . (id >< g) = (f >< g)
than that
mapFst f . mapSnd g = (f >< g)
Now, though, there's &&& in Control.Arrow, and that subsumes
><, so I'm nolonger enthusiastic about (><) (though I might
define it locally in circumstances where I think my readers
would be unfamiliar with &&&).
One of the considerations is that once you put a name into a
library, you'll have the devil's own job getting it out
again if you decide it was a mistake.
Jón
--
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
More information about the Libraries
mailing list