What a good name for the natural transformation of `forall a. ma & # 8594; (Identity βŠ• m) a`?

I found that I am writing a bunch of functions with a signature

a -> Either longComplicatedType (m longComplicatedType) 

So, I decided that I needed an alias

 type SomeAlias ma = Either a (ma) 

making it just a natural transformation of the functor m isomorphic to forall a. ma -> (Identity βŠ• m) a forall a. ma -> (Identity βŠ• m) a .

At first I wanted to call it MaybeN or MaybeF , since he used the functor m or nothing. But Maybe a is isomorphic to 1 βŠ• a , and Identity not a terminal object in the endofunctors category, Proxy is equal , therefore MaybeN fa should be Either (Proxy a) (fa) .

Is there an existing name for forall a. ma -> (Identity βŠ• m) a forall a. ma -> (Identity βŠ• m) a , can I steal from another place? Otherwise, there is a more elegant name than IdentityOr ?

+5
source share
2 answers

What you ask exists under the name Lift

 data Lift ga = Pure a | Other (ga) 

This can be defined as a type synonym in terms of Sum and Identity

 data Sum :: (k -> Type) -> (k -> Type) -> (k -> Type) where InL :: fa -> (Sum fg) a InR :: ga -> (Sum fg) a newtype Identity :: Type -> Type where Identity :: a -> Identity a type Lift ga = (Sum Identity g) a 

but it will not give you an instance of Applicative or Alternative .

Sum fg is only applicative under very specific circumstances (taking into account the monoidal natural transformation forall xx. (Applicative g, Applicative f) => g xx -> f xx ) (in more detail: Abstracts with application and Construction of applicative functors ). It exists for

 mnt :: forall xx. Applicative f => Identity xx -> f xx mnt (Identity x) = pure x 

and Lift g is a special case.

+2
source

This seems isomorphic to InR from Data.Functor.Sum with f = Identity and g = m :

 data Sum fga = InL (fa) | InR (ga) 

There was quite a bit of bikeshedding when the library committee chose these names; you can find other alternatives there.

+3
source

All Articles