Created
July 26, 2013 13:59
-
-
Save Blaisorblade/6089067 to your computer and use it in GitHub Desktop.
An alternative desugaring for implicit case classes (kudos to @Toxaris!).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
class Foo(bar: Int) | |
implicit object Foo extends (Int => Foo) { | |
def apply(bar: Int) = new Foo(bar) | |
} | |
// Exiting paste mode, now interpreting. | |
defined class Foo | |
defined module Foo | |
scala> def bar(a: Foo) = a | |
bar: (a: Foo)Foo | |
scala> bar(1) | |
res0: Foo = Foo@3e91cc3a | |
scala> bar(Foo(1)) | |
res1: Foo = Foo@44fc63be |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It turns out that this was already discussed on the ML, and turned down for unclear reasons.