Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created July 11, 2012 07:34
Show Gist options
  • Save tonymorris/3088749 to your computer and use it in GitHub Desktop.
Save tonymorris/3088749 to your computer and use it in GitHub Desktop.
Scala WTF
case class Person(name: String, age: Int)
object Person
case class OtherPerson(name: String, age: Int)
object T {
def ap[A, B, C](f: (A, B) => C)(a: A, b: B): C =
f(a, b)
// This fails the compiler[1]...
// val p = ap(Person)("Fred", 20)
val q = ap(Person(_: String, _: Int))("Fred", 20)
// ...but this doesn't. Why?
val op = ap(OtherPerson)("Fred", 20)
}
/*
[1]
error: type mismatch;
found : Person.type (with underlying type object Person)
required: (?, ?) => ?
val p = ap(Person)("Fred", 20)
*/
@asflierl
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment