Last active
November 2, 2017 14:32
-
-
Save bergmark/9dd0d90b96720e59e29a45d8a0a59909 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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