diff --git a/doc/JA/syntax/04_function.md b/doc/JA/syntax/04_function.md index f4a2fd6e9..46b1ed423 100644 --- a/doc/JA/syntax/04_function.md +++ b/doc/JA/syntax/04_function.md @@ -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 @@ -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`の糖衣構文です。 -

Previous | Next

diff --git a/tests/const_fn.er b/tests/const_fn.er new file mode 100644 index 000000000..49b80b53f --- /dev/null +++ b/tests/const_fn.er @@ -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}