optics-dev / optics-dev/Monocle
Remove polymorphic optics
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 1.7k
- Forks
- 207
- Avg merge
- 7h 59m
- Merged PRs (30d)
- 5
Description
Standard optics work between two types A and B. There is a generalisation of optics called polymorphic optics that takes four type parameters, generally called S, T, A, and B. This generalisation let us change the type of the value targetted by an optic. For example, if you have an Option[Int] (S), you may want to transform an Int (A) into a String (B), resulting in an Option[String] (T). Polymorphic optics can express standard optics (aka monomorphic optics) as an alias, type Lens[A, B] = PolyLens[A, A, B, B].
Polymorphic optics have several issues:
- They obfuscate the code, especially for people new to Scala or functional programming.
- Most optics properties are defined in term of monomorphic optics (see discussion)
- Polymorphic optics often require explicit type annotations because Scala has eager type inference. It is particularly annoying when Scala fails to infer one of the four type parameters; in this case, users have to specify all types manually (see examples).
- Most optics in the wild are monomorphic (I might be biased). Polymorphic updates can be achieved by other means, e.g.
maportraverse.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with core/shared/src/test/scala-2.13/monocle/TypeInferenceTest.scala, which demonstrates the affected type inference. Inventory the polymorphic optics and their usages, then verify that the remaining monomorphic optics and related tests still compile after removal.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- developer-experience
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100