-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple phantom functions are FunctionN/ImplicitFunctionN types where all parameters are of the same phantom universe. They are synthesized in the object defining the phantom universe. It main usage should be through `(MyPhantom) => Int` nothation as it does not require any imports.
- Loading branch information
1 parent
2a25799
commit 8234c77
Showing
40 changed files
with
577 additions
and
50 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
class PhantomFun1NoApply extends Function1[Boo.Casper, Unit] // error: class PhantomFun1NoApply needs to be abstract, since def apply: (p0: Casper)Unit is not defined | ||
|
||
object Boo extends Phantom { | ||
type Casper <: this.Any | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
class PhantomFun1 extends Boo.Function2[Boo.Casper, Int, Unit] { // error: Type argument Int does not conform to upper bound Boo.Any | ||
def apply(x1: Boo.Casper, x2: Int): Unit = () | ||
} | ||
|
||
class PhantomFun2 extends Boo.Function2[Int, Boo.Casper, Unit] { // error: Type argument Int does not conform to upper bound Boo.Any | ||
def apply(x1: Boo.Casper, x2: Int): Unit = () | ||
} | ||
|
||
class Fun extends Function2[Int, Int, Unit] { | ||
def apply(x1: Int, x2: Int): Unit = () | ||
} | ||
|
||
object Boo extends Phantom { | ||
type Casper <: this.Any | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
// TODO: Importing an object that exends phantom makes FunctionN refere to the Boo.FunctionN | ||
// We should be carefull with this. Use a waring when importing Boo._ or disallow it. | ||
// Or put funtions in an inner object in the Phantom trait, for example scala.Phantom.Functions | ||
|
||
import Boo._ | ||
|
||
class Fun extends Function1[Int, Unit] { // error: Type argument Int does not conform to upper bound Boo.Any | ||
def apply(x1: Int): Unit = () | ||
} | ||
|
||
object Boo extends Phantom { | ||
type Casper <: this.Any | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
class Fun { | ||
def a = (x1: Int, x2: Boo.B) => x1 // error: Int and Boo.B are in different universes. They cannot be combined in function arguments. | ||
def b: (Int, Boo.B) => Unit = (x1, x2) => x1 // error: Int and Boo.B are in different universes. They cannot be combined in function arguments. | ||
|
||
def c = (x1: Foo.F, x2: Boo.B) => x1 // error: Foo.F and Boo.B are in different universes. They cannot be combined in function arguments. | ||
def d: (Foo.F, Boo.B) => Unit = (x1, x2) => x1 // error: Foo.F and Boo.B are in different universes. They cannot be combined in function arguments. | ||
} | ||
|
||
object Boo extends Phantom { | ||
type B <: this.Any | ||
} | ||
|
||
object Foo extends Phantom { | ||
type F <: this.Any | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Blinky1.apply() | ||
Blinky1.apply() | ||
Blinky1.apply() |
Oops, something went wrong.