Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
205 additions
and
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,134 +1,22 @@ | ||
--- | ||
out: typelevelexp.html | ||
out: stringinterpolation.html | ||
--- | ||
|
||
[1]: stdtypcon.html | ||
String Interpolation | ||
-------------------- | ||
|
||
Type-Level Expressions | ||
---------------------- | ||
|
||
### Type references | ||
|
||
Use `TYPE_REF(tree|sym|"C")` to explicitly convert symbols, names, and trees into types: | ||
|
||
```scala | ||
(VAL("pos", TYPE_REF(REF("board") DOT "Coord")): Tree) | ||
``` | ||
|
||
This prints as: | ||
|
||
``` | ||
val pos: board.Coord | ||
``` | ||
|
||
### Applied types | ||
|
||
Applied types are written by calling `TYPE_OF(typ|"C", ...)` on a type: | ||
|
||
```scala | ||
REF("x") withType(ListClass TYPE_OF IntClass) | ||
``` | ||
|
||
This prints as: | ||
String interpolations are written using `INTERP(sym|"x", arg, ...)`: | ||
|
||
```scala | ||
(x: List[Int]) | ||
``` | ||
INTERP(StringContext_s, LIT("Jello"), LIT(1), REF("x")) | ||
|
||
### Type constructors | ||
|
||
treehugger DSL provides built-in type constructors, which will be covered more [later][1]: | ||
|
||
```scala | ||
REF("x") withType(TYPE_LIST(IntClass)) | ||
REF("y") withType(TYPE_TUPLE(IntClass, IntClass)) | ||
REF("z") withType(IntClass TYPE_=> IntClass) | ||
INTERP("s", LIT("Hello"), LIT(1), REF("x")) | ||
``` | ||
|
||
These examples print as: | ||
|
||
```scala | ||
(x: List[Int]) | ||
(y: (Int, Int)) | ||
(z: Int => Int) | ||
``` | ||
|
||
### Refined types | ||
|
||
Refined types are written by calling `TYPE_WITH (typ|"C", ...)` on a type: | ||
|
||
```scala | ||
(VAL("x", TYPE_REF("A") TYPE_WITH "B"): Tree) | ||
``` | ||
|
||
This prints as: | ||
|
||
```scala | ||
val x: A with B | ||
``` | ||
|
||
### Singleton types | ||
|
||
Singleton type are written using `TYPE_SINGLETON(tree)`: | ||
|
||
```scala | ||
(VAL("x", TYPE_SINGLETON(THIS)): Tree) | ||
``` | ||
|
||
This prints as: | ||
|
||
```scala | ||
val x: this.type | ||
``` | ||
|
||
### Structural types | ||
|
||
Structural types are written using `TYPE_STRUCT(tree, ...)`: | ||
|
||
```scala | ||
REF("x") withType(TYPE_STRUCT( | ||
DEF("close", UnitClass) | ||
)) | ||
``` | ||
|
||
This prints as: | ||
|
||
```scala | ||
(x: ({ def close: Unit })) | ||
``` | ||
|
||
### Type projections | ||
|
||
Type projections are written by calling `TYPE_# (typ|"C")` on a type: | ||
|
||
```scala | ||
REF("x") withType(TYPE_STRUCT( | ||
TYPEVAR("L") withTypeParams(TYPEVAR("A")) := | ||
REF("Const") APPLYTYPE ("M", "A") | ||
) TYPE_#("L")) | ||
``` | ||
|
||
This prints as: | ||
|
||
```scala | ||
(foo: ({ type L[A] = Const[M, A] })#L) | ||
``` | ||
|
||
### Existential types | ||
|
||
Existential types are written by calling `TYPE_FORSOME(tree, ...)` on a type: | ||
|
||
```scala | ||
(DEF("foo") | ||
withParams(PARAM("arg", TYPE_LIST( | ||
TYPE_REF(REF("x") DOT "T")) TYPE_FORSOME( | ||
VAL("x", "Outer") | ||
)))).tree | ||
``` | ||
|
||
This prints as: | ||
s"Jello\${1}\$x" | ||
|
||
```scala | ||
def foo(arg: List[x.T] forSome { val x: Outer }) | ||
s"Hello\${1}\$x" | ||
``` | ||
|
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,134 @@ | ||
--- | ||
out: typelevelexp.html | ||
--- | ||
|
||
[1]: stdtypcon.html | ||
|
||
Type-Level Expressions | ||
---------------------- | ||
|
||
### Type references | ||
|
||
Use `TYPE_REF(tree|sym|"C")` to explicitly convert symbols, names, and trees into types: | ||
|
||
```scala | ||
(VAL("pos", TYPE_REF(REF("board") DOT "Coord")): Tree) | ||
``` | ||
|
||
This prints as: | ||
|
||
``` | ||
val pos: board.Coord | ||
``` | ||
|
||
### Applied types | ||
|
||
Applied types are written by calling `TYPE_OF(typ|"C", ...)` on a type: | ||
|
||
```scala | ||
REF("x") withType(ListClass TYPE_OF IntClass) | ||
``` | ||
|
||
This prints as: | ||
|
||
```scala | ||
(x: List[Int]) | ||
``` | ||
|
||
### Type constructors | ||
|
||
treehugger DSL provides built-in type constructors, which will be covered more [later][1]: | ||
|
||
```scala | ||
REF("x") withType(TYPE_LIST(IntClass)) | ||
REF("y") withType(TYPE_TUPLE(IntClass, IntClass)) | ||
REF("z") withType(IntClass TYPE_=> IntClass) | ||
``` | ||
|
||
These examples print as: | ||
|
||
```scala | ||
(x: List[Int]) | ||
(y: (Int, Int)) | ||
(z: Int => Int) | ||
``` | ||
|
||
### Refined types | ||
|
||
Refined types are written by calling `TYPE_WITH (typ|"C", ...)` on a type: | ||
|
||
```scala | ||
(VAL("x", TYPE_REF("A") TYPE_WITH "B"): Tree) | ||
``` | ||
|
||
This prints as: | ||
|
||
```scala | ||
val x: A with B | ||
``` | ||
|
||
### Singleton types | ||
|
||
Singleton type are written using `TYPE_SINGLETON(tree)`: | ||
|
||
```scala | ||
(VAL("x", TYPE_SINGLETON(THIS)): Tree) | ||
``` | ||
|
||
This prints as: | ||
|
||
```scala | ||
val x: this.type | ||
``` | ||
|
||
### Structural types | ||
|
||
Structural types are written using `TYPE_STRUCT(tree, ...)`: | ||
|
||
```scala | ||
REF("x") withType(TYPE_STRUCT( | ||
DEF("close", UnitClass) | ||
)) | ||
``` | ||
|
||
This prints as: | ||
|
||
```scala | ||
(x: ({ def close: Unit })) | ||
``` | ||
|
||
### Type projections | ||
|
||
Type projections are written by calling `TYPE_# (typ|"C")` on a type: | ||
|
||
```scala | ||
REF("x") withType(TYPE_STRUCT( | ||
TYPEVAR("L") withTypeParams(TYPEVAR("A")) := | ||
REF("Const") APPLYTYPE ("M", "A") | ||
) TYPE_#("L")) | ||
``` | ||
|
||
This prints as: | ||
|
||
```scala | ||
(foo: ({ type L[A] = Const[M, A] })#L) | ||
``` | ||
|
||
### Existential types | ||
|
||
Existential types are written by calling `TYPE_FORSOME(tree, ...)` on a type: | ||
|
||
```scala | ||
(DEF("foo") | ||
withParams(PARAM("arg", TYPE_LIST( | ||
TYPE_REF(REF("x") DOT "T")) TYPE_FORSOME( | ||
VAL("x", "Outer") | ||
)))).tree | ||
``` | ||
|
||
This prints as: | ||
|
||
```scala | ||
def foo(arg: List[x.T] forSome { val x: Outer }) | ||
``` | ||
|
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version=0.2.3 | ||
version=0.3.0 | ||
toc = collapse |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.