Skip to content
This repository was archived by the owner on Jan 5, 2025. It is now read-only.

Commit 45d1ece

Browse files
authored
2.6章 summary (#88)
* 翻訳開始 * 翻訳完了 * セルフチェック
1 parent 06d7d86 commit 45d1ece

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

functional-programming-lean/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
- [プロジェクトの開始](./hello-world/starting-a-project.md)
2020
- [Worked Example: `cat`](./hello-world/cat.md)
2121
- [Additional Conveniences](./hello-world/conveniences.md)
22-
- [Summary](./hello-world/summary.md)
22+
- [まとめ](./hello-world/summary.md)
2323
- [休憩:命題・証明・リストの添え字アクセス](props-proofs-indexing.md)
2424
- [オーバーロードと型クラス](type-classes.md)
2525
- [正の整数](type-classes/pos.md)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,134 @@
1+
<!--
12
# Summary
3+
-->
24

5+
# まとめ
6+
7+
<!--
38
## Evaluation vs Execution
9+
-->
10+
11+
## 評価 vs 実行
412

13+
<!--
514
Side effects are aspects of program execution that go beyond the evaluation of mathematical expressions, such as reading files, throwing exceptions, or triggering industrial machinery.
615
While most languages allow side effects to occur during evaluation, Lean does not.
716
Instead, Lean has a type called `IO` that represents _descriptions_ of programs that use side effects.
817
These descriptions are then executed by the language's run-time system, which invokes the Lean expression evaluator to carry out specific computations.
918
Values of type `IO α` are called _`IO` actions_.
1019
The simplest is `pure`, which returns its argument and has no actual side effects.
20+
-->
21+
22+
副作用とはファイルの読み込み・例外の発生・産業機械の起動など、数式の評価を超えたプログラムの実行についての側面です。ほとんどの言語では評価中に副作用が発生することを許可していますが、Leanでは許可していません。その代わりに、Leanには `IO` という型があり、副作用を使用するプログラムの **記述** を表現します。これらの記述は言語のランタイムシステムによって実行されます。このランタイムシステムはLeanの式の評価器を呼び出して特定の計算を実行します。`IO α` 型の値は **`IO` アクション** と呼ばれます。最も単純なものは `pure` で、これは引数をそのまま返し、実際の副作用を持ちません。
1123

24+
<!--
1225
`IO` actions can also be understood as functions that take the whole world as an argument and return a new world in which the side effect has occurred.
1326
Behind the scenes, the `IO` library ensures that the world is never duplicated, created, or destroyed.
1427
While this model of side effects cannot actually be implemented, as the whole universe is too big to fit in memory, the real world can be represented by a token that is passed around through the program.
28+
-->
1529

30+
`IO` アクションは世界全体を引数として受け取り、副作用が発生した新しい世界を返す関数として理解することもできます。その裏では、`IO` ライブラリは世界が決して複製されたり、新しく作られたり、破壊されたりしないことを保証しています。全宇宙は大きすぎてメモリに収まらないため、この副作用のモデルを実際に実装することはできませんが、現実の世界をプログラム中で受け渡されるトークンとして表現することができます。
31+
32+
<!--
1633
An `IO` action `main` is executed when the program starts.
1734
`main` can have one of three types:
35+
-->
36+
37+
`IO` アクション `main` はプログラムが開始された時に実行されます。`main` は以下3つのうちどれかの型を持ちます:
38+
39+
<!--
1840
* `main : IO Unit` is used for simple programs that cannot read their command-line arguments and always return exit code `0`,
1941
* `main : IO UInt32` is used for programs without arguments that may signal success or failure, and
2042
* `main : List String → IO UInt32` is used for programs that take command-line arguments and signal success or failure.
43+
-->
2144

45+
* `main : IO Unit` はコマンドライン引数を読むことができず、常に終了コード `0` を返す単純なプログラムに使われます。
46+
* `main : IO UInt32` は成功または失敗を知らせる引数のないプログラムに使われます。
47+
* `main : List String → IO UInt32` はコマンドライン引数を取り、成功または失敗を知らせるプログラムに使われます。
2248

49+
<!--
2350
## `do` Notation
51+
-->
52+
53+
## `do` 記法
2454

55+
<!--
2556
The Lean standard library provides a number of basic `IO` actions that represent effects such as reading from and writing to files and interacting with standard input and standard output.
2657
These base `IO` actions are composed into larger `IO` actions using `do` notation, which is a built-in domain-specific language for writing descriptions of programs with side effects.
2758
A `do` expression contains a sequence of _statements_, which may be:
59+
-->
60+
61+
Leanの標準ライブラリは、ファイルからの読み込みや書き込み、標準入出力とのやり取りなどの作用を表す基本的な `IO` アクションを数多く提供しています。これらの基本的な `IO` アクションは、副作用を持つプログラムを書くための組み込みドメイン固有言語である `do` 記法を使ってより大きな `IO` アクションにまとめることができます。`do` 記法は以下のような一連の **** を含んでいます:
62+
63+
<!--
2864
* expressions that represent `IO` actions,
2965
* ordinary local definitions with `let` and `:=`, where the defined name refers to the value of the provided expression, or
3066
* local definitions with `let` and `←`, where the defined name refers to the result of executing the value of the provided expression.
67+
-->
3168

69+
* `IO` アクションを表す式
70+
* `let``:=` を使った通常のローカル定義、定義された名前は渡された式の値を指します。
71+
* `let``` を使ったローカル定義、定義された名前は渡された式の値を実行した結果を指します。
72+
73+
<!--
3274
`IO` actions that are written with `do` are executed one statement at a time.
75+
-->
76+
77+
`do` で記述された `IO` アクションは一度に1文ずつ実行されます。
3378

79+
<!--
3480
Furthermore, `if` and `match` expressions that occur immediately under a `do` are implicitly considered to have their own `do` in each branch.
3581
Inside of a `do` expression, _nested actions_ are expressions with a left arrow immediately under parentheses.
3682
The Lean compiler implicitly lifts them to the nearest enclosing `do`, which may be implicitly part of a branch of a `match` or `if` expression, and gives them a unique name.
3783
This unique name then replaces the origin site of the nested action.
84+
-->
3885

86+
さらに、`do` の直下にある `if` 式と `match` 式は、暗黙的にそれぞれの分岐に `do` があると見なされます。`do` 式の内部では、**ネストされたアクション** は括弧の直下にある左矢印で記述された式です。Leanコンパイラは、暗黙的にそれらを最も近い `do``match``if` の分岐に暗黙的にあるものも含みます)に結び付け、一意な名前を付けます。この一意な名前によってネストされたアクションのもともとの位置を置き換えます。
3987

88+
<!--
4089
## Compiling and Running Programs
90+
-->
4191

92+
## プログラムのコンパイルと実行
93+
94+
<!--
4295
A Lean program that consists of a single file with a `main` definition can be run using `lean --run FILE`.
4396
While this can be a nice way to get started with a simple program, most programs will eventually graduate to a multiple-file project that should be compiled before running.
97+
-->
98+
99+
`lean --run FILE` というコマンドで `main` 定義を持つ単一ファイルで構成されるLeanプログラムを実行することができます。これは簡単なプログラムの実行には良い方法ですが、ほとんどのプログラムは最終的に複数のファイルを持つプロジェクトへと成長するので、実行する前にコンパイルする必要があります。
44100

101+
<!--
45102
Lean projects are organized into _packages_, which are collections of libraries and executables together with information about dependencies and a build configuration.
46103
Packages are described using Lake, a Lean build tool.
47104
Use `lake new` to create a Lake package in a new directory, or `lake init` to create one in the current directory.
48105
Lake package configuration is another domain-specific language.
49106
Use `lake build` to build a project.
107+
-->
50108

109+
Leanのプロジェクトは、依存関係やビルド構成に関する情報とともにライブラリや実行可能ファイルのコレクションである **パッケージ** へと編成されます。パッケージはLeanのビルドツールであるLakeを使って記述します。新しいディレクトリにLakeパッケージを作成するには `lake new` を、現在のディレクトリに作成するには `lake init` を使用します。Lakeのパッケージ構成もドメイン固有言語です。プロジェクトをビルドするには `lake build` を使用します。
110+
111+
<!--
51112
## Partiality
113+
-->
114+
115+
## 部分性
52116

117+
<!--
53118
One consequence of following the mathematical model of expression evaluation is that every expression must have a value.
54119
This rules out both incomplete pattern matches that fail to cover all constructors of a datatype and programs that can fall into an infinite loop.
55120
Lean ensures that all `match` expressions cover all cases, and that all recursive functions are either structurally recursive or have an explicit proof of termination.
121+
-->
56122

123+
式評価の数学的モデルに従うことから導かれる結論の1つとして、すべての式が値を持たなければならないということがあります。これにより、データ型のすべてのコンストラクタをカバーできない不完全なパターンマッチと無限ループに陥る可能性のあるプログラムの両方が除外されます。Leanはすべての `match` 式がすべてのケースをカバーすること、すべての再帰関数は構造的に再帰的であるか停止の明示的な証明があることを保証します。
124+
125+
<!--
57126
However, some real programs require the possibility of looping infinitely, because they handle potentially-infinite data, such as POSIX streams.
58127
Lean provides an escape hatch: functions whose definition is marked `partial` are not required to terminate.
59128
This comes at a cost.
60129
Because types are a first-class part of the Lean language, functions can return types.
61130
Partial functions, however, are not evaluated during type checking, because an infinite loop in a function could cause the type checker to enter an infinite loop.
62131
Furthermore, mathematical proofs are unable to inspect the definitions of partial functions, which means that programs that use them are much less amenable to formal proof.
132+
-->
133+
134+
しかし、実際のプログラムの中にはPOSIXのストリームのように無限ループする可能性のあるデータを扱うために、無限ループの可能性を必要とするものがあります。これに対してLeanは逃げ道を用意しています:定義が `partial` とマークされた関数は停止する必要がありません。これには代償が伴います。型はLean言語の第一級であるため、関数は型を返すことができます。しかし、関数が無限ループに入ると型チェッカが無限ループも入る可能性があるため、部分関数は型チェック中に評価されません。さらに、数学的な証明では部分関数の定義を検査することができないため、部分関数を使用するプログラムは形式的な証明にあまり適していません。

0 commit comments

Comments
 (0)