-
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.
Add a run test for poly context bounds; cleanup typer changes
- Loading branch information
1 parent
f292ac5
commit f9db9fa
Showing
4 changed files
with
42 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
42 | ||
a string | ||
Kate is 27 years old | ||
42 and a string | ||
a string and Kate is 27 years old | ||
Kate is 27 years old and 42 |
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,30 @@ | ||
import scala.language.experimental.modularity | ||
import scala.language.future | ||
|
||
trait Show[X]: | ||
def show(x: X): String | ||
|
||
given Show[Int] with | ||
def show(x: Int) = x.toString | ||
|
||
given Show[String] with | ||
def show(x: String) = x | ||
|
||
case class Person(name: String, age: Int) | ||
|
||
given Show[Person] with | ||
def show(x: Person) = s"${x.name} is ${x.age} years old" | ||
|
||
type Shower = [X: Show] => X => String | ||
val shower: Shower = [X: {Show as show}] => (x: X) => show.show(x) | ||
|
||
type DoubleShower = [X: Show] => X => [Y: Show] => Y => String | ||
val doubleShower: DoubleShower = [X: {Show as show1}] => (x: X) => [Y: {Show as show2}] => (y: Y) => s"${show1.show(x)} and ${show2.show(y)}" | ||
|
||
object Test extends App: | ||
println(shower(42)) | ||
println(shower("a string")) | ||
println(shower(Person("Kate", 27))) | ||
println(doubleShower(42)("a string")) | ||
println(doubleShower("a string")(Person("Kate", 27))) | ||
println(doubleShower(Person("Kate", 27))(42)) |