Skip to content

Instantly share code, notes, and snippets.

@bergmark
Last active November 2, 2017 14:32
Show Gist options
  • Save bergmark/9dd0d90b96720e59e29a45d8a0a59909 to your computer and use it in GitHub Desktop.
Save bergmark/9dd0d90b96720e59e29a45d8a0a59909 to your computer and use it in GitHub Desktop.
#!/usr/bin/env scala
trait DbRep[A] {
type Rep
}
class Email
object EmailRep extends DbRep[Email] {
override type Rep = String
}
class Foo
object FooRep extends DbRep[Foo] {
override type Rep = Int
}
object Main extends App {
// error: an implicit parameter section must be last
// def lower[A](a: A)(implicit dbRep: DbRep[A])(implicit eq: dbRep.Rep =:= String): A = ???
def map[A](dbRep: DbRep[A])(f: dbRep.Rep => dbRep.Rep): A => A = { a => a }
def lower[A](dbRep: DbRep[A])(a: A)(implicit eq: dbRep.Rep =:= String): A = map[A](dbRep)(x => x)(a)
println(lower[Email](EmailRep)(new Email))
// error: Cannot prove that FooRep.Rep =:= String.
println(lower[Foo](FooRep)(new Foo))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment