Created
January 22, 2012 05:47
-
-
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
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
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) | |
^ |
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
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