Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions doc/JA/syntax/04_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,16 @@ assert add_hundred(1) == 101
そのかわり、計算をコンパイル時に行うことができるというメリットがあります。

```python
Add(X, Y: Nat): Nat = X + Y
assert Add(1, 2) == 3
Add(X, Y: Nat) = X + Y
Add: |X: Nat, Y: Nat|({X}, {Y}) -> {Add(X, Y)}
Three = Add(1, 2)
Three: {3}

Factorial 0 = 1
Factorial(X: Nat): Nat = X * Factorial(X - 1)
assert Factorial(10) == 3628800
Factorial: |X: Nat|{X} -> {Factorial(X)}
Fact10 = Factorial(10)
Fact10: {3628800}

math = import "math"
Sin X = math.sin X # ConstantError: this function is not computable at compile time
Expand Down Expand Up @@ -309,8 +313,6 @@ f(a, b) # TypeError: f() takes 1 positional argument but 2 were given
f((a, b)) # OK
```

関数型`T -> U`は実際のところ、`(T,) -> U`の糖衣構文です。

<p align='center'>
<a href='./03_declaration.md'>Previous</a> | <a href='./05_builtin_funcs.md'>Next</a>
</p>
7 changes: 7 additions & 0 deletions tests/const_fn.er
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Fib: |N: Nat| {N} -> {Fib N}
Fib 0 = 0
Fib 1 = 1
Fib N: Nat = Fib(N-1) + Fib(N-2)

Fib10 = Fib 10
Fib10: {55}