Created
April 25, 2013 13:40
-
-
Save tpolecat/5459761 to your computer and use it in GitHub Desktop.
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
trait Fresh[N] { | |
def fresh:N | |
} | |
class Term[N](implicit F: Fresh[N]) { | |
def foo = "made a " + F.fresh | |
} | |
val ti = new Term[Int] // won't compile | |
implicit val FreshInt = new Fresh[Int] { | |
val nums = (1 to Int.MaxValue).iterator | |
def fresh = nums.next | |
} | |
val ti = new Term[Int] // now it will compile | |
ti.foo // made a 1 | |
ti.foo // made a 2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment