Search code examples
haskellfunctor

Does this Functor combinator have a name?


I have a combinator C and a Functor instance defined as follows:

data C f1 f2 a = C (f1 a) (f2 a)

instance
  ( Functor f1
  , Functor f2
  )
    => Functor (C f1 f2)
  where
    fmap g (C a b) = C (fmap g a) (fmap g b)

In plain English I might describe C as a product type in which the fmap instance distributes.

My implementation here is fine for my purposes here, but I want to know if there is a proper name for this combinator in the haskell or category-theoretic jargon, so that I might project to future users of this library what this does, or even use existing code instead if such exists.

Does this combinator already have a name?


Solution

  • It's a functor product, defined in the Data.Functor.Product module from the base library. From the link:

    data Product f g a = Pair (f a) (g a)
    
    instance (Functor f, Functor g) => Functor (Product f g) where
        fmap f (Pair x y) = Pair (fmap f x) (fmap f y)
    

    (To be precise, both are just a products of higher-kinded types, not necessarily functors, but C f g and Product f g are only functors if f and g are both functors as well.)