我看的是强的和封闭的profunctors类:
class Profunctor p where
dimap :: (a' -> a) -> (b -> b') -> p a b -> p a' b'
class Profunctor p => Strong p where
strong :: p a b -> p (c, a) (c, b)
class Profunctor p => Closed p where
closed :: p a b -> p (c -> a) (c -> b)((,)是一个对称的双函数,因此它等同于"profunctors“包中的定义。)
我注意到(->) a和(,) a都是内函数器。看起来Strong和Closed有一个相似的形式:
class (Functor f, Profunctor p) => C f p where
c :: p a b -> p (f a) (f b)事实上,如果我们看一下法律,有些法律也有类似的形式:
strong . strong ≡ dimap unassoc assoc . strong
closed . closed ≡ dimap uncurry curry . closed
lmap (first f) . strong ≡ rmap (first f) . strong
lmap (. f) . closed ≡ rmap (. f) . closed这两种情况都是一般情况的特例吗?
发布于 2019-03-13 10:06:38
您可以将Choice添加到列表中。Strong和Choice (或者叫cartesian和cocartesian,Jeremy Gibbons这样称呼它们)都是Tambara模块的例子。我在我关于profunctor optics的博客文章中(跳到讨论部分)讨论了包含Closed的一般模式,名称为Related。
发布于 2019-03-13 09:33:23
非常有趣。这不是真正的答案,只是想法..。
因此,我们需要的是(,)和(->)上的抽象,它提供了assoc/curry和first/precompose的泛化。我将解决前者:
class Isotropic f where
lefty :: f a (f b c) -> f (a,b) c
righty :: f (a,b) c -> f a (f b c)
-- lefty ≡ righty⁻¹
instance Isotropic (,) where
lefty (a,(b,c)) = ((a,b),c)
righty ((a,b),c) = (a,(b,c))
instance Isotropic (->) where
lefty = uncurry
righty = curry很简单。问题是,有没有其他这样的例子?当然还有一个微不足道的
newtype Biconst c a b = Biconst c
instance Isotropic (Biconst c) where
lefty (Biconst c) = Biconst c
righty (Biconst c) = Biconst c然后生成的profunctor
class Profunctor p => Stubborn p where
stubborn :: p a b -> p (Biconst d c a) (Biconst d c b)也可以写成
class Profunctor p => Stubborn p where
stubborn :: p a b -> p d d但是这个例子似乎也太微不足道了,没有任何用处:
instance Stubborn (->) where
stubborn _ = id
instance (Monad m) => Stubborn (Kleisli m) where
stubborn (Kleisli _) = Kleisli pure
instance (Monoid m) => Stubborn (Forget m) where
stubborn (Forget _) = Forget $ const mempty我怀疑(,)和(->)真的是唯一有用的用例,因为它们分别是“自由双函数器”/“自由函数器”。
https://stackoverflow.com/questions/55132048
复制相似问题