You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This might seem a little silly, but it would be very useful for typeclass programing. With inheritance, it is nice to be able to declare an interface using a val or def on a trait and then "implement" it with a param on a case class. With typeclasses, you can already do a similar thing:
but that extra ceremony in the extension is a little ugly. Similarly, as suggested by this thread, it would be nice to be able to call "static" methods on a typeclass (those not naturally written as extension (self: Self) def ... using static syntax:
traitTypeclass[Self]:defstatic(x: Int):IntobjectTypeclass:extension [Self](n: Typeclass.type)(usingtc: Typeclass[Self])
privatedeftcCeremony= tc
exporttcCeremony.*deftakesTypeclass[T:Typeclass](t: T):Int=Typeclass.static(5)
// instead of def takesTypeclass[T: Typeclass](t: T): Int = summon[Typeclass[T]].static(5)// or def takesTypeclass[T](t: T)(using tc: Typeclass[T]): Int = tc.static(5)
I think this is probably a very simple change, but I could not figure out how to do it myself.
The text was updated successfully, but these errors were encountered:
ckipp01
transferred this issue from lampepfl/dotty-feature-requests
May 31, 2023
Uh oh!
There was an error while loading. Please reload this page.
After this PR, it is possible to export members in extension clauses like so:
It would be nice to be able to do
This might seem a little silly, but it would be very useful for typeclass programing. With inheritance, it is nice to be able to declare an interface using a
val
ordef
on atrait
and then "implement" it with a param on acase class
. With typeclasses, you can already do a similar thing:but that extra ceremony in the extension is a little ugly. Similarly, as suggested by this thread, it would be nice to be able to call "static" methods on a typeclass (those not naturally written as
extension (self: Self) def ...
using static syntax:I think this is probably a very simple change, but I could not figure out how to do it myself.
The text was updated successfully, but these errors were encountered: