Data.Functor.{Product,Sum} functions
Mario Blažević
blamario at ciktel.net
Sat Dec 24 17:19:47 UTC 2016
On 2016-12-23 07:02 PM, Baldur Blöndal wrote:
> Let's see if any of these are useful (a lot more at
> https://ghc.haskell.org/trac/ghc/ticket/13026)
>
> (||||) :: (f a -> b) -> (g a -> b) -> ((Sum f g) a -> b)
> f |||| g = \case
> InL fa -> f fa
> InR ga -> g ga
The corresponding destructor function in Data.Either is called either:
either :: (a -> c) -> (b -> c) -> Either
<http://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Either.html#t:Either>
a b -> c
Thus the most logical name for the Sum destructor would be sum. You can
always import Data.Functor.Product qualified as Product to avoid
clashes. In the same vein, I propose adding
uncurry :: (f a -> g a -> b) -> Product f g a -> b
uncurry f (Pair a b) = f a b
> (&&&&) :: (a -> f b) -> (a -> g b) -> (a -> (Product f g) b)
> (f &&&& g) a = f a `Pair` g a
I'm not fond of that name. Also, f &&&& g == uncurry Pair . (f &&& g)
More information about the Libraries
mailing list