16

In their paper on profunctor optics, Pickering et al. state that

The term ‘profunctor’ comes from category theory, although much of the categorical structure gets lost in translation.

That seems odd and kind of unique to me, as other algebraic structures I know of (pairs, monoids, functors, categories, etc.) "do not seem" to suffer the same fate, in languages like Haskell and PureScript – with quotes because I'm happy to be proven wrong.

A while ago, I played a bit with the family of profunctors and found them very tractable, especially in the context of optics. My interest got picked again after seeing them come up in the context of monad transformers. I need to rewatch this a couple of times as I don't get the details, but on principle it is perfectly clear. So I can't help wondering:

  • what are those properties? why don't they materialise in the language?
  • what effort would be necessary to bring them in, if at all possible?
  • what would be the benefits of doing so? In particular, could they help solve the issues Ed mentions at the end of his talk?
duplode
  • 33,731
  • 7
  • 79
  • 150
Regis Kuckaertz
  • 991
  • 5
  • 14
  • 3
    Well... at the very least functors and monads are quite restricted, in that they are only endofunctors on Hask. There are other categories, even in haskell, worth considering, but our `Monad` does not capture them. – luqui Apr 28 '18 at 18:25
  • I see. Although I know endofunctors map a category to itself, I have a very limited view on what it prevents us from doing (is that what Conal Eliott's paper "Compiling to categories" is all about?). I guess my question is, even with that limitation, do Haskell functors keep their algebraic properties? – Regis Kuckaertz Apr 29 '18 at 08:12
  • 2
    One limitation is that profunctor laws cannot be expressed in Haskell. A profunctor maps pairs of morphisms -- in Haskell that's the purpose of dimap -- and it should map identity morphisms to identities, and composition to composition. You can check these laws by hand using equational reasoning. Then there is the fact that profunctors form a category. Natural transformations between profunctors may be approximated by polymorphic functions but, in Haskell, they are restricted by parametricity. Optics, in particular, require polymorphism over profunctor categories with various constraints. – Bartosz Milewski Apr 29 '18 at 18:11
  • Thank you. I’ve read your “profunctors as relations” post, it provided good food for thought; I’ll need to re-read a few times, as some statements still escape me. Especially since, if they form a category, I should be able to write an instance of Category for any Profunctor. I’ll try to write one and see where that leads me. – Regis Kuckaertz May 01 '18 at 07:03
  • @RegisKuckaertz profunctors form a category, where composition is https://hackage.haskell.org/package/profunctors-5.3/docs/Data-Profunctor-Composition.html; **not** every `Profunctor` is a `Category` (many are though, but e.g. `Tagged` cannot be, there is no `id`). Various classes -- like `Strong` -- form sub-categories, there is e.g. `(Strong p, Strong q) => Strong (Procompose p q)` instance: profunctor optics use these sub-category classes to form various optics. – phadej Feb 26 '19 at 18:01

0 Answers0