Skip to content

Instantly share code, notes, and snippets.

@sleexyz
Created August 15, 2016 16:06
Show Gist options
  • Select an option

  • Save sleexyz/d3821a95576451d8eea2476c0db077ed to your computer and use it in GitHub Desktop.

Select an option

Save sleexyz/d3821a95576451d8eea2476c0db077ed to your computer and use it in GitHub Desktop.
class ContextBoundsSyntax {
trait Monoid[A] {
def zero:A
def append (a:A, b:A) : A
}
implicit object AdditiveInt extends Monoid[Int] {
def zero = 0
def append (a:Int, b:Int) = a + b
}
def gimmeZero[T : Monoid](x: T): T = {
implicitly[Monoid[T]].zero
}
def gimmeZero2[T: Monoid](x: T): T = {
implicitly[Monoid[T]].zero
}
def foo() {
gimmeZero(100)
}
}
@sleexyz

sleexyz commented Aug 15, 2016

Copy link
Copy Markdown
Author

gimmeZero and gimmeZero2 are the same disassembled with javap -c

  public <T> T gimmeZero(T, ContextBoundsSyntax$Monoid<T>);
    Code:
       0: getstatic     #41                 // Field scala/Predef$.MODULE$:Lscala/Predef$;
       3: aload_2
       4: invokevirtual #45                 // Method scala/Predef$.implicitly:(Ljava/lang/Object;)Ljava/lang/Object;
       7: checkcast     #47                 // class ContextBoundsSyntax$Monoid
      10: invokeinterface #51,  1           // InterfaceMethod ContextBoundsSyntax$Monoid.zero:()Ljava/lang/Object;
      15: areturn

  public <T> T gimmeZero2(T, ContextBoundsSyntax$Monoid<T>);
    Code:
       0: getstatic     #41                 // Field scala/Predef$.MODULE$:Lscala/Predef$;
       3: aload_2
       4: invokevirtual #45                 // Method scala/Predef$.implicitly:(Ljava/lang/Object;)Ljava/lang/Object;
       7: checkcast     #47                 // class ContextBoundsSyntax$Monoid
      10: invokeinterface #51,  1           // InterfaceMethod ContextBoundsSyntax$Monoid.zero:()Ljava/lang/Object;
      15: areturn

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