Skip to content

Instantly share code, notes, and snippets.

@Blaisorblade
Created July 26, 2013 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Blaisorblade/6089067 to your computer and use it in GitHub Desktop.
Save Blaisorblade/6089067 to your computer and use it in GitHub Desktop.
An alternative desugaring for implicit case classes (kudos to @Toxaris!).
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
@Blaisorblade
Copy link
Author

It turns out that this was already discussed on the ML, and turned down for unclear reasons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment