什么是自然转型的好名字`forall a。 m a - > (身份⊕m)a`?

时间:2015-08-27 12:44:52

标签: haskell

我发现自己用签名

编写了一堆函数
a -> Either longComplicatedType (m longComplicatedType)

所以我决定需要一个别名

type SomeAlias m a = Either a (m a)

使其成为仿函数m的自然变换,与forall a. m a -> (Identity ⊕ m) a同构。

起初我很想将其命名为MaybeNMaybeF,因为它要么使用仿函数m,要么就是没有。但Maybe a1 ⊕ aIdentity isn't the terminal object in the category of endofunctors, Proxy is同构,因此MaybeN f a应为Either (Proxy a) (f a)

我是否可以从其他地方偷取forall a. m a -> (Identity ⊕ m) a的现有名称?如果失败了,是否有一个比IdentityOr更优雅的名字?

2 个答案:

答案 0 :(得分:3)

InRf = Identityg = m data Sum f g a = InL (f a) | InR (g a) 似乎与var details = { videoId: vidId[i], kind: 'youtube#video' } var part= 'snippet'; var resource = { snippet: { playlistId: newPlaylist.id, resourceId: details } }; var insertVideo = YouTube.PlaylistItems.insert(resource, part); 同构:

int lists[30]

图书馆委员会选择这些名称时有Data.Functor.Sum;你可能会在那里找到一些其他选择。

答案 1 :(得分:2)

您要求的内容名称为Lift

data Lift g a = Pure a | Other (g a)

根据SumIdentity

,可以将其定义为类型同义词
data Sum :: (k -> Type) -> (k -> Type) -> (k -> Type) where
  InL :: f a -> (Sum f g) a
  InR :: g a -> (Sum f g) a

newtype Identity :: Type -> Type where
  Identity :: a -> Identity a

type Lift g a = (Sum Identity g) a

但这不会为您提供ApplicativeAlternative个实例。

Sum f g仅在非常具体的情况下适用(给定幺半形自然变换forall xx. (Applicative g, Applicative f) => g xx -> f xx)(更多信息:Abstracting with ApplicativesConstructing Applicative Functors)。

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

Lift g就是这种特殊情况。