Skip to content

Instantly share code, notes, and snippets.

@tpolecat
Created April 25, 2013 13:40
Show Gist options
  • Save tpolecat/5459761 to your computer and use it in GitHub Desktop.
Save tpolecat/5459761 to your computer and use it in GitHub Desktop.
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