标签: profunctor

亵渎者和箭头之间的关系是什么?

显然,每个人Arrow都是一个Strong教练.确实^>>>>^对应lmaprmap.而first'second'只是同firstsecond.同样,每个人ArrowChoice也都是Choice.

与箭相比,影响者缺乏的是构成它们的能力.如果我们添加构图,我们会得到一个箭头吗?换句话说,如果(强)profunctor也是一个类别,它是否已经是一个箭头?如果没有,有什么遗漏?

haskell arrows functor category-theory profunctor

22
推荐指数
2
解决办法
2446
查看次数

profunctors的哪些属性不能用于Haskell/PureScript?

在他们关于探测器光学的论文中,皮克林等人.说明

"profunctor"这个词来自类别理论,尽管很多分类结构在翻译中丢失了.

这对我来说似乎有点奇怪和独特,因为我所知道的其他代数结构(对,幺半群,仿函数,类别等)"似乎"在Haskell和PureScript等语言中遭受同样的命运 - 引用因为我很高兴被证明是错的.

不久之前,我和一些发明家一起玩了一下,发现它们很容易处理,特别是在光学方面.看到它们出现在monad变形金刚的背景下后,我的兴趣再次被选中.我需要重复这几次,因为我没有得到细节,但原则上它是非常清楚的.所以我不禁疑惑:

  • 那些属性是什么?他们为什么不在语言中实现?
  • 如果可能的话,需要付出多少努力才能将他们带入?
  • 这样做有什么好处?特别是,他们能帮助解决Ed在谈话结束时提到的问题吗?

haskell monad-transformers category-theory purescript profunctor

12
推荐指数
0
解决办法
283
查看次数

强壮的和封闭的专家的一般化

我当时正在研究强壮的和封闭的专业人士:

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。似乎StrongClosed具有类似的形式:

class (Functor f, Profunctor p) …
Run Code Online (Sandbox Code Playgroud)

haskell functor category-theory profunctor

9
推荐指数
1
解决办法
112
查看次数

为什么不能在 GHC 中强制超功能?

我有以下类型,它基于论文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)

haskell coercion profunctor

8
推荐指数
1
解决办法
154
查看次数

类比为Profunctors的免费monad

我们可以定义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对于潜在的类比而言是同构的 …

haskell free-monad profunctor

7
推荐指数
1
解决办法
255
查看次数

“Wither”的 Profunctor 表示是什么?

克里斯·彭纳 (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 代表?如果是这样,那是什么?

haskell lenses profunctor

5
推荐指数
1
解决办法
137
查看次数

笛卡尔(Profunctor)的例子?

我正在通过以下代码示例,发现很难弄清楚如何使用( - >)和(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 category-abstractions profunctor

3
推荐指数
1
解决办法
145
查看次数