在他们关于探测器光学的论文中,皮克林等人.说明
"profunctor"这个词来自类别理论,尽管很多分类结构在翻译中丢失了.
这对我来说似乎有点奇怪和独特,因为我所知道的其他代数结构(对,幺半群,仿函数,类别等)"似乎"在Haskell和PureScript等语言中遭受同样的命运 - 引用因为我很高兴被证明是错的.
不久之前,我和一些发明家一起玩了一下,发现它们很容易处理,特别是在光学方面.看到它们出现在monad变形金刚的背景下后,我的兴趣再次被选中.我需要重复这几次,因为我没有得到细节,但原则上它是非常清楚的.所以我不禁疑惑:
haskell monad-transformers category-theory purescript profunctor
我当时正在研究强壮的和封闭的专业人士:
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)
Run Code Online (Sandbox Code Playgroud)
((,)是对称bifunctor,因此它等效于“ profunctors”包中的定义。)
我注意到这两个(->) a和(,) a是endofunctors。似乎Strong并Closed具有类似的形式:
class (Functor f, Profunctor p) …Run Code Online (Sandbox Code Playgroud) 我有以下类型,它基于论文Cooutining folds with hyperfunctions:
newtype Hyper a b = Hyper { invoke :: Hyper b a -> b }
Run Code Online (Sandbox Code Playgroud)
它的第一个参数是逆变的,第二个参数是协变的,所以它是一个 profunctor:
instance Profunctor Hyper where
lmap f = go where
go (Hyper h) = Hyper $ \(Hyper k) -> h $ Hyper $ f . k . go
rmap g = go where
go (Hyper h) = Hyper $ \(Hyper k) -> g $ h $ Hyper $ k . go
dimap f g = go where
go …Run Code Online (Sandbox Code Playgroud) 我们可以定义data Free f a = Pure a | Free (f (Free f a))等等Functor f => Monad (Free f).
如果我们定义
data T f a b = R a | S b | T (f a (T f a b))有一些我们类似M如此Profunctor f => M (T f a),在那里class Profunctor f where dimap :: (a -> b) -> (c -> d) -> f b c -> f a d?
自从我注意到以来,我一直在想,Data.Comp.Term.Context并且Free对于潜在的类比而言是同构的 …
克里斯·彭纳 (Chris Penner) 的这篇文章谈到了“枯萎的光学”;可用于从结构中过滤项目的光学元件。
本文对这些光学器件使用以下“Van Laarhoven”表示:
type Wither s t a b = forall f. Alternative f => (a -> f b) -> s -> f t
Run Code Online (Sandbox Code Playgroud)
大多数(如果不是全部)Van Laarhoven 光学具有等效的 profunctor 表示。例如镜头:
type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t
Run Code Online (Sandbox Code Playgroud)
相当于:
type Lens s t a b = forall p. Strong p => p a b -> p s t
Run Code Online (Sandbox Code Playgroud)
是否Wither也有 Profuctor 代表?如果是这样,那是什么?
我正在通过以下代码示例,发现很难弄清楚如何使用( - >)和(Star f)一旦他们实现'first'并成为Cartisian的成员.
有人可以提供一些容易理解的例子吗?谢谢.
-- Intuitively a profunctor is cartesian if it can pass around additional
-- context in the form of a pair.
class Profunctor p => Cartesian p where
first :: p a b -> p (a, c) (b, c)
first = dimap swapP swapP . second
second :: p a b -> p (c, a) (c, b)
second = dimap swapP swapP . first
instance Cartesian (->) where
first :: (a -> b) -> (a, c) …Run Code Online (Sandbox Code Playgroud) haskell ×7
profunctor ×7
functor ×2
arrows ×1
coercion ×1
free-monad ×1
lenses ×1
purescript ×1