Skip to content

Instantly share code, notes, and snippets.

@rampion
Created January 22, 2012 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rampion/1655807 to your computer and use it in GitHub Desktop.
Save rampion/1655807 to your computer and use it in GitHub Desktop.
When is a tuple not a tuple, and other scala type error ambiguities
scala> def k( j : (Int => Int) => Int ) : Int = j(_+1)
k: (j: Int => Int => Int)Int
scala> def p(q : Int => Int) : Int = q(0)
p: (q: Int => Int)Int
scala> def z = (x : Int) => (y : Int) => x + y
z: Int => Int => Int
scala> k(p)
res1: Int = 1
scala> k(z)
<console>:10: error: type mismatch;
found : Int => Int => Int
required: Int => Int => Int
k(z)
^
scala> def f(x : Int, y : Int) : Int = x + y
f: (x: Int, y: Int)Int
scala> def g(z : (Int, Int)) : Int = z._1 + z._2
g: (z: (Int, Int))Int
scala> def h(c : (Int, Int) => Int) : Int = c(1,2)
h: (c: (Int, Int) => Int)Int
scala> f(1,2)
res0: Int = 3
scala> g(1,2)
res1: Int = 3
scala> h(f)
res2: Int = 8
scala> h(g)
<console>:10: error: type mismatch;
found : (Int, Int) => Int
required: (Int, Int) => Int
h(g)
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment