forked from MetaBorgCube/scala.mstx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_01.scala
44 lines (35 loc) · 1.1 KB
/
example_01.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
STATIX ok
SCALAC ok
//
// name juggling using different kinds of imports, and qualified access
//
object Numbers {
type I = Int;
def const(i1: I)(i2: I): Int = i1;
};
object Functions {
def const(i1: Int)(i2: Int): Int = i1;
def flip(f: Int => Int => Int)(i1 : Int)(i2 : Int): Int = {
f(i2)(i1)
};
// A nested Functions module.
// In Rust, importing the content of the outer Functions object
// would result in ambiguity, because the inner one would be revealed and
// make the import ambiguous.
// In Scala this is fine, because imports open only in subsequent scope.
object Functions {};
};
object Test {
import Numbers.{I => Number, _}; // const is in scope via the wildcard import
def compute_42(i : Number): Number = {
val x: Int = const(i)(18);
// explicit (renaming) import shadows outer wildcard import of const,
// and we hide the const from the Functions object.
import Functions.{flip => const, const => _};
{
// the outer const refers to the one from the lexical scope
// being the renamed flip
const(Numbers.const)(x)(42)
}
};
};