Adding swap/compose functions to Data.Tuple and Data.Function

John Wiegley johnw at
Tue Nov 20 20:28:15 CET 2012

>>>>> Edward Kmett <ekmett at> writes:

> Data.Tuple already contains swap.

Yeah, and I'm finding it just fine with Hoogle now.  I'm not sure how I was
led into thinking it didn't exist, but I had reached for it one day and my
hands came up empty.

>         compose :: [(a -> a)] -> a -> a
>         compose = foldr (.) id
>         composeM :: [(a -> m a)] -> a -> m a
>         composeM = foldr (<=<) return

> The composition of them is obvious, and the suggested names already exist
> commonly in a lot of third party code for all sorts of purposes.

> The pain of adoption plus the annoyance of trying to find them exceeds, to
> me, the utility of adding them.

Fair enough.  It does seem that the idiom deserves a name, though, considering
how often I've come across it, but perhaps that ship has sailed.

John Wiegley
FP Complete                         Haskell tools, training and consulting               johnw on #haskell/

More information about the Libraries mailing list