-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
46 changed files
with
3,599 additions
and
1,238 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- 配列の型は推論できる。 | ||
- どのように推論するか考え中 | ||
|
||
``` | ||
var x: number[] = [1, 2, 3]; | ||
``` |
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,54 @@ | ||
``` | ||
interface Position { | ||
fn getX(): number; | ||
fn getY(): number; | ||
} | ||
interface Drawable { | ||
fn draw(); | ||
} | ||
struct Player { | ||
name: string, | ||
x: number, | ||
y: number, | ||
} | ||
impl Player { | ||
fn getName(): number { | ||
return this.name; | ||
} | ||
} | ||
impl Player : Position { | ||
fn getX(): number { | ||
return this.x; | ||
} | ||
fn getY(): number { | ||
return this.y; | ||
} | ||
} | ||
impl Player : Drawable { | ||
fn draw() { | ||
// ... | ||
} | ||
} | ||
fn showCharInfo(char: Position & Drawable) { | ||
print(char.getX()); | ||
print(char.getY()); | ||
print(char.draw()); | ||
} | ||
fn main() { | ||
var player = new Player { | ||
name: "you", | ||
x: 0, | ||
y: 0, | ||
}; | ||
console.write(player.getName()); | ||
showCharInfo(player); | ||
} | ||
``` |
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,15 @@ | ||
- 関数宣言 | ||
- 引数の型は明示しなければならない。 | ||
- 戻り値の型は明示しなければならない。 | ||
- 指定されない場合は`void`型として扱われる。 | ||
- (静的解析) 指定した戻り値の型の値が返されない場合はエラーとする。 | ||
|
||
``` | ||
fn add(x: number, y: number): number { | ||
return x + y; | ||
} | ||
fn main() { | ||
var x: number = add(1, 2); | ||
} | ||
``` |
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,32 @@ | ||
## 二項演算子 | ||
- 演算子の左側の式から型を推論する。 | ||
|
||
``` | ||
var x: number = 1 + 2; | ||
// 3 | ||
``` | ||
|
||
``` | ||
var x: bool = (1 == 1); | ||
// true | ||
``` | ||
|
||
``` | ||
var x: bool = (1 < 2); | ||
// true | ||
``` | ||
|
||
``` | ||
var x: bool; | ||
x = (true && true); | ||
// true | ||
x = (true || false); | ||
// true | ||
``` | ||
- `e1 || e2`の演算でe1を評価した結果がtrueの場合はe2の評価は行われない。 | ||
|
||
## 単項演算子 | ||
``` | ||
var x: bool = !true; | ||
// false | ||
``` |
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 @@ | ||
- タプルの型は推論できる。 | ||
- タプルの要素数、各要素から型を推論する。 | ||
|
||
``` | ||
var x: (number, number) = (1, 2); | ||
``` |
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,21 @@ | ||
- 変数の型は推論できる。 | ||
- 初期値として与えられた式の型を推論して、変数の型とする。 | ||
|
||
宣言・代入 | ||
``` | ||
var x: number = 1; | ||
x = 2; | ||
``` | ||
``` | ||
var x: number; | ||
x = 1; | ||
``` | ||
``` | ||
var x; | ||
x = 1; | ||
``` | ||
|
||
参照 | ||
``` | ||
console.writeNum(x); | ||
``` |
Oops, something went wrong.