我发现自己用签名写了一堆函数
a -> Either longComplicatedType (m longComplicatedType)所以我决定我需要一个化名
type SomeAlias m a = Either a (m a)使之成为函子m上的一个自然变换,与forall a. m a -> (Identity ⊕ m) a同构。
起初,我很想把它命名为MaybeN或MaybeF,因为它要么使用函子m,要么什么也不使用。但是Maybe a与1 ⊕ a和是同构,所以MaybeN f a应该是Either (Proxy a) (f a)。
我可以从其他地方盗取forall a. m a -> (Identity ⊕ m) a的现有名称吗?如果没有,还有比IdentityOr更优雅的名字吗?
发布于 2017-05-11 02:37:57
您所要求的东西以Lift的名义存在。
data Lift g a = Pure a | Other (g a)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但这不会给您提供一个Applicative或Alternative实例。
Sum f g只是在非常特殊的情况下(给定一个单线自然变换forall xx. (Applicative g, Applicative f) => g xx -> f xx)的应用程序(更多信息:http://comonad.com/reader/2012/abstracting-with-applicatives/和http://www.staff.city.ac.uk/~ross/papers/Constructors.html)。这是为了
mnt :: forall xx. Applicative f => Identity xx -> f xx
mnt (Identity x) = pure xLift g就是这个特例。
发布于 2015-08-27 23:24:32
这似乎与InR与Data.Functor.Sum的f = Identity和g = m同构。
数据和f_g_a= InL (f _ a) _ InR (g _ a)
然而,当库委员会选择这些名称时,就有了相当多的自行车;您可能会在那里找到一些其他的替代方案。
https://stackoverflow.com/questions/32249756
复制相似问题