Adding swap/compose functions to Data.Tuple and Data.Function
Andreas Abel
andreas.abel at ifi.lmu.de
Tue Nov 20 20:19:02 CET 2012
On 20.11.2012 20:14, John Wiegley wrote:
> Moving discussion from http://hackage.haskell.org/trac/ghc/ticket/7435:
>
> I propose adding the following three functions to Data.Tuple and
> Data.Function, respectively:
>
> swap :: (a,b) -> (b,a)
> swap = snd &&& fst
+1
> Fairly obvious, but strangely missing.
>
> compose :: [(a -> a)] -> a -> a
> compose = foldr (.) id
>
> composeM :: [(a -> m a)] -> a -> m a
> composeM = foldr (<=<) return
>
> This can be done with Endo, of course, but the result is awkward. The idiom of
> composing a list of endomorphisms occurs often enough that you can Google for
> it.
+0.5 (a bit in doubt whether these are common enough).
--
Andreas Abel <>< Du bist der geliebte Mensch.
Theoretical Computer Science, University of Munich
Oettingenstr. 67, D-80538 Munich, GERMANY
andreas.abel at ifi.lmu.de
http://www2.tcs.ifi.lmu.de/~abel/
More information about the Libraries
mailing list