Created
May 15, 2014 19:19
-
-
Save coacoas/8d7f90b99a0c93ca0fc5 to your computer and use it in GitHub Desktop.
TypeClass in Scala
This file contains hidden or 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
/* | |
* Copyright (c) 2001, 2014, Object Innovation, Inc. All Rights Reserved. | |
* | |
* This software is published under the terms of the Object Innovation License | |
* version 1.1, a copy of which has been included with this distribution in the | |
* LICENSE.TXT file. Learn more at http://www.bridgegatetei.com | |
*/ | |
package com.oidev.bridgegate | |
/** | |
* Created by bcarlson on 5/15/14. | |
*/ | |
object Example { | |
def wiggle[A](a: A): String = ??? | |
trait Show[A] { | |
def show(a: A): String | |
} | |
def wobble[A : Show](a: A): String = | |
implicitly[Show[A]].show(a) | |
implicit object IntShow extends Show[Int] { | |
def show(a: Int): String = s"Integer: ${a.toString}" | |
} | |
wobble(3) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment