Syntax for polymorphic values.#54
Conversation
|
I fixed the 2.10 build failure and made the new functionality opt-in via |
6c5c4a9 to
8409672
Compare
ν[T].m[A, B[_], ...](e)
is rewritten to
new T { def m[A, B[_], ...] = e }
(`ν` is the lowercase Greek letter "Nu" (/njuː/) and stands for `new`.)
In case `m` has just one *-kinded type parameter that is
is not referenced from `e`, it can be omitted:
ν[T].m(e)
is rewritten to
new T { def m[A] = e }
where `A` is a fresh name.
If the method name is `apply`, it can be omitted:
ν[T][A, B[_], ...](e)
is rewritten to
new T { def apply[A, B[_], ...] = e }
The previous two shortcuts can be combined:
ν[T](e)
is rewritten to
new T { def apply[A] = e }
where `A` is a fresh name.
Λ[A, B[_], ...](e) : T
is rewritten to
new T { def apply[A, B[_], ...] = e
Note that explicit type `T` of the Λ-expression is required.
|
I changed the name from I also added alternative I updated the description above to reflect these changes. |
Adapted from typelevel/kind-projector#54.
|
I published this functionality as a separate plugin: P∀scal. I consider polymorphic values (including existing polymorphic lambdas) a separate concern from kind-projector's type lambdas through type projections. Nevertheless, I'm leaving this open for a while in case people want to see this in kind-projector anyway. |
|
can you support the plain English spellings too? In Emacs I have a prettify-greek mode which will render these things as UTF-8 but save as ASCII to disk. It also makes it a lot easier for me to type... |
|
I could do For typing, I have just installed Greek keyboard layout. |
|
I think it would need to be the lowercase versions for prettify-greek to work (it'll use capitals) |
|
For kind-projector, |
|
I'm going to close this for the following reasons:
|
This is another attempt at convenient syntax for polymorphic values. This PR addresses #37 and supersedes #44.
The syntax
is rewritten to
(The symbol "ν" is the Greek lowercase letter "Nu" (/njuː/) and stands for
new.)In case
mhas just one *-kinded type parameter which is not referenced frome, it can be omitted:ν[T].m(e)is rewritten to
where
Ais a fresh name.If the method name is
apply, it can be omitted:is rewritten to
The previous two shortcuts can be combined:
ν[T](e)is rewritten to
where
Ais a fresh name.There is also an alternative syntax using Λ (Greek uppercase letter Lambda)
which is equivalent to
i.e.
When using Λ-syntax, type parameters cannot be omitted, and method name is (currently) assumed to be
apply. Note also that the typeTof the whole Λ-expression has to be specified (cannot be inferred, since kind-projector runs before typer).See the test cases in
polyval.scalafor some examples.