kowainik / prolens

👓 Profunctor based lightweight implementation of Lenses
Mozilla Public License 2.0
74 stars 4 forks source link

Kleisli instead of Fun #26

Closed ilyakooo0 closed 3 years ago

ilyakooo0 commented 3 years ago

It doesn't seem obvious to me why Fun is distinct from Kleisli (if it is not distinct, then why reimplement it?):

https://github.com/kowainik/prolens/blob/559e106d424b559a70e22df49f57a7d672ea4e65/src/Prolens.hs#L62-L65

Screenshot 2020-10-11 at 13 21 33

The Functor instance also seems to be identical.

chshersh commented 3 years ago

@ilyakooo0 Yes, we are aware that this is Kleisli, and we've introduced Fun intentionally. And there are several reasons for this:

  1. Kleisli has Functor instance only since GHC-8.10, but we want to support the latest 3 major GHC versions. With our own type, we can do this easily without CPP and orphan instances.
  2. This type appears in type signatures, and Kleisli sounds scarier. One of our library goal is teaching and learning material, and we want to make the concept of profunctor optics more accessible. So even beginners and Haskellers not experienced in category theory will be able to understand the concepts.
  3. Functor instance for Kleisli is derived and I suspect that it doesn't have {-# INLINE #-} annotation. With our own implementation, we have more control over performance.

Also, Fun is a WIP name. If you have better begiiner-friendly suggestions (other than Kleisli), we are happy to hear them :slightly_smiling_face:

chshersh commented 3 years ago

Closing the issue since the question was answered.