SI-2712-fix plugin
This is proof of concept fix to SI-2712 implemented as a compiler plugin. There is also a PR to fix this directly in scalac.
The implementation is based on a simple algorithm as suggested by Paul Chiusano in the comments on SI-2712:
Treat the type constructor as curried and partially applied, we treat a prefix as constants and solve for the suffix.
For the example in the ticket, unifying M[A]
with Int => Int
, this unifies as,
M[t] = [t][Int => t]
A = Int
More detailed explanations can also be found at this gist Explaining Miles's Magic by @djspiewak and the readme of the demo project.
One place to discuss this fix is at typelevel's gitter room.
Usage
Binary release artefacts are published to the Sonatype OSS Repository Hosting service and synced to Maven Central. To use the plugin in your project add the following to its sbt build file,
addCompilerPlugin("com.milessabin" % "si2712fix-plugin" % "1.1.0" cross CrossVersion.full)
If you intended to use the @unifyRightToLeft
annotation to enable right-to-left unify rule please add the following
as well
libraryDependencies += "com.milessabin" % "si2712fix-library" % "1.1.0" cross CrossVersion.full
More context about right to left rule can be found in this issue comment.
Examples
An example project can be found at milessabin/si2712fix-demo
Caveats
Please note that currently this plugin and the Macro Paradise plugin are incompatible because they
both hook into the Scala compiler via the same exclusive mechanism. The two projects are working on this problem and
hope to have a solution by the time of Scala Days ... watch this space!
Update: as of version 1.1.0 this plugin and the Macro Paradise plugin are compatible!
Participation
This project supports the Typelevel code of conduct and wants all of its channels (Gitter, github, etc.) to be welcoming environments for everyone.
Building the plugin
This plugin is built with SBT 0.13.11 or later, and its master branch is built with Scala 2.11.8 and 2.10.6 by default.
Contributors
- Adelbert Chang adelbertc@gmail.com @adelbertchang
- Kailuo Wang kailuo.wang@gmail.com @kailuowang
- Miles Sabin miles@milessabin.com @milessabin
- Your name here :-)