Asa*_*din 7 haskell category-theory traversable
AFunList是 Twan van Laarhoven 在这篇博文中发明的一种数据类型。Bartosz Milewski 给出的一个小变化如下所示:
data FunList a b t = Done t
| More a (FunList a b (b -> t))
Run Code Online (Sandbox Code Playgroud)
关于这种数据类型的一个有趣的事实是,如果我们稍微调整一下类型参数,我们会得到一个Profunctor:
data FunList t b a
= Done t
| More a (FunList (b -> t) b a)
mapResult :: (a -> b) -> FunList a x y -> FunList b x y
mapResult f (Done x) = Done $ f x
mapResult f (More a r) = More a $ mapResult (f .) r
instance Profunctor (FunList t)
where
dimap _ _ (Done t) = Done t
dimap f g (More a r) = More (g a) $ dimap f g $ mapResult (. f) r
Run Code Online (Sandbox Code Playgroud)
服从dimap id id = id和dimap (f . g) (h . i) = dimap g h . dimap f i
该类Profunctor有几个有用的子类,它们代表带有附加设备的 profunctor 族(在范畴论意义上)。具体来说,我们可以谈论具有“强度”的 profunctors:
class Profunctor p => Strong t1 t2 p
where
pstrength :: p a b -> p (t1 a x) (t2 b x)
Run Code Online (Sandbox Code Playgroud)
法律由“双范畴中的强单子”的分类概念决定(这在Kazuyuki Asada 的“箭头是强单子”中详细解释)。
类似地,由于 profunctor 是“只是”functor,我们可以寻找 profunctor 是否是幺半群的:
class Profunctor p => SemigroupalProfunctor t1 t2 t3 p
where
combine :: t3 (p a b) (p c d) -> p (t1 a c) (t2 b d)
class SemigroupalProfunctor t1 t2 t3 p => MonoidalProfunctor t1 i1 t2 i2 t3 i3 p
where
unit :: i3 -> p i1 i2
Run Code Online (Sandbox Code Playgroud)
根据幺半群函子的定义给出的定律。
t1、t2、t3和i1、i2、、、和 的一些有趣选择分别i3是(,)、和。EitherThese()Void
问题是改组后FunList实例化了哪些类?一个关于它为什么遵循法律的论点的实现将非常好,正确性的证明将是极好的。
TODO:在这里专门列出每个班级的法律清单
| 归档时间: |
|
| 查看次数: |
92 次 |
| 最近记录: |