Skip to content

initial steps towards I18n of tutorial docs #3238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
169 changes: 169 additions & 0 deletions data/tutorials/getting-started/1_00_install_OCaml.ja.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
---
id: installing-ocaml
title: OCamlのインストール
description: |
このページでは、OCamlとOCaml Platformツールのインストール方法を説明します。 |
この手順は、Windows、およびLinuxやmacOSのようなUnix系システムで動作します。
category: "First Steps"
language: Japanese
---

このガイドでは、OCamlの最小限のインストールについて説明します。これには、パッケージマネージャーと[コンパイラ](#installation-on-unix-and-macos)自体のインストールが含まれます。また、ビルドシステム、エディタのサポート、その他いくつかの重要なプラットフォームツールもインストールします。

このページでは、Linux、macOS、Windows、および\*BSD向けの最近のOCamlバージョンのインストール手順を説明します。Dockerについては、opamの設定時を除き、Linuxの手順が適用されます。

**注**: OCamlとそのツールは、[コマンドラインインターフェース(CLI)またはシェル](https://www.youtube.com/watch?v=0PxTAn4g20U)を介してインストールします。

## opamのインストール

OCamlには公式のパッケージマネージャー [opam](https://opam.ocaml.org/) があり、ユーザーはOCamlのツールやライブラリをダウンロードしてインストールできます。opamはまた、異なるバージョンのOCamlを必要とする様々なプロジェクトを扱うことを容易にします。

opamはOCamlコンパイラもインストールします。他の選択肢も存在しますが、OCamlをインストールする最良の方法はopamです。OCamlはほとんどのLinuxディストリビューションでパッケージとして利用可能ですが、しばしばバージョンが古いことがあります。

opamをインストールするには、[システムのパッケージマネージャーを使用する](https://opam.ocaml.org/doc/Install.html#Using-your-distribution-39-s-package-system)か、[バイナリディストリビューション](https://opam.ocaml.org/doc/Install.html#Binary-distribution)をダウンロードします。詳細はこれらのリンクにありますが、便宜上、ここではパッケージディストリビューションを使用します。

**macOSの場合**

[Homebrew](https://brew.sh/) を使ってインストールする場合:

```shell
brew install opam
```

または[MacPorts](https://www.macports.org/) を使っている場合:

```shell
port install opam
```

**注**: macOSでopamをインストールするのはかなり簡単ですが、Homebrewのインストールの仕組みが変更されたため、後で問題が発生する可能性があります。新しいMacで使われているM1プロセッサーなどのARM64環境では、実行ファイルが見つからない場合があります。これに対処するのはかなり複雑な手順になる可能性があるため、このインストールガイドの妨げにならないように、[短いARM64修正ドキュメント](/docs/arm64-fix)(英語)を作成しました。

**Linuxの場合**

Linuxでは、システムのパッケージマネージャーを使用してスーパーユーザーとしてopamをインストールすることが望ましいです。opamのサイトで、[すべてのインストール方法の詳細](https://opam.ocaml.org/doc/Install.html)を確認できます。opamのバージョン2.0以上が、サポートされているすべてのLinuxディストリビューションでパッケージ化されています。サポートされていないLinuxディストリビューションを使用している場合は、コンパイル済みのバイナリをダウンロードするか、ソースからopamをビルドしてください。

DebianまたはUbuntuにインストールする場合:

```shell
sudo apt-get install opam
```

Arch Linuxにインストールする場合:

```shell
sudo pacman -S opam
```

**注**: Ubuntuでも使用されているDebianのopamパッケージは、OCamlコンパイラを推奨依存関係としています。デフォルトでは、そのような依存関係はインストールされます。OCamlなしでopamのみをインストールしたい場合は、次のようなコマンドを実行する必要があります:

```shell
sudo apt-get install --no-install-recommends opam
```

**Windowsの場合**

[WinGet](https://github.com/microsoft/winget-cli) を使ってopamをインストールするのが最も簡単です:

```shell
PS C:\> winget install Git.Git OCaml.opam
```

**バイナリディストリビューション**

opamの最新リリースが必要な場合は、バイナリディストリビューションを介してインストールしてください。UnixやmacOSでは、まず `gcc`、`build-essential`、`curl`、`bubblewrap`、`unzip` といったシステムパッケージをインストールする必要があります。これらのパッケージ名は、お使いのオペレーティングシステムやディストリビューションによって異なる場合があることに注意してください。また、このスクリプトは内部で `sudo` を呼び出すことにも注意してください。

次のコマンドは、お使いのシステムに適用される最新バージョンのopamをインストールします:

```shell
bash -c "sh <(curl -fsSL https://opam.ocaml.org/install.sh)"
```

Windowsでは、wingetパッケージはopamの開発者によってメンテナンスされており、[GitHubでリリースされているバイナリ](https://github.com/ocaml/opam/releases)を使用しますが、同等のPowerShellスクリプトを使用してインストールすることもできます:

```powershell
Invoke-Expression "& { $(Invoke-RestMethod https://opam.ocaml.org/install.ps1) }"
```

**上級のWindowsユーザー向け**: CygwinやWSL2に詳しい場合は、[OCaml on Windows](/docs/ocaml-on-windows)(英語)ページに記載されている他のインストール方法があります。

## opamの初期化

opamをインストールしたら、初期化する必要があります。そのためには、一般ユーザーとして次のコマンドを実行してください。完了するまでに数分かかることがあります。

```shell
opam init -y
```

**注**: Dockerコンテナ内で `opam init` を実行している場合は、サンドボックス機能を無効にする必要があります。これは `opam init --disable-sandboxing -y` を実行することで行えます。特権付きDockerコンテナを実行しない限り、これが必要です。

`opam init` の出力の最後に表示される指示に従って、初期化を完了させてください。通常、これは以下のようになります:

Unixの場合:
```
eval $(opam env)
```

Windowsのコマンドプロンプトの場合:
```
for /f "tokens=*" %i in ('opam env') do @%i
```

PowerShellの場合:
```powershell
(& opam env) -split '\r?\n' | ForEach-Object { Invoke-Expression $_ }
```

opamの初期化には数分かかることがあります。インストールと設定が完了するのを待つ間、[A Tour of OCaml](/docs/tour-of-ocaml)(英語)を読み始めてください。

**注**: opamは_スイッチ_と呼ばれるものを管理できます。これは複数のOCamlプロジェクトを切り替える際に重要です。しかし、この「はじめの一歩」シリーズのチュートリアルでは、スイッチは必要ありません。興味があれば、[opamスイッチの紹介](/docs/opam-switch-introduction)(英語)を読むことができます。

**インストールで問題がありましたか?** 必ず[最新のリリースノート](https://opam.ocaml.org/blog/opam-2-2-0/)(英語)を読んでください。問題は <https://github.com/ocaml/opam/issues> または <https://github.com/ocaml-windows/papercuts/issues> で報告できます。

## Platformツールのインストール

OCamlコンパイラとopamパッケージマネージャーのインストールに成功したので、次はOCamlでの完全な開発体験を得るために必要な[OCaml Platformツール](https://ocaml.org/docs/platform)(英語)をいくつかインストールしましょう。

- [UTop](https://github.com/ocaml-community/utop): モダンな対話的トップレベル (REPL: Read-Eval-Print Loop)
- [Dune](https://dune.build): 高速で多機能なビルドシステム
- [`ocaml-lsp-server`](https://github.com/ocaml/ocaml-lsp): Language Server Protocolを実装し、VS Code、Vim、EmacsなどでOCamlのエディタサポートを可能にします。
- [`odoc`](https://github.com/ocaml/odoc): OCamlコードからドキュメントを生成します。
- [OCamlFormat](https://opam.ocaml.org/packages/ocamlformat/): OCamlコードを自動的にフォーマットします。

これらのツールはすべて、単一のコマンドでインストールできます:

```shell
opam install ocaml-lsp-server odoc ocamlformat utop
```

これで準備は万端、コーディングを始める準備ができました。

## インストールの確認

すべてが正しく動作しているか確認するために、UTopトップレベルを起動してみましょう:

```shell
$ utop
────────┬─────────────────────────────────────────────────────────────┬─────────
│ Welcome to utop version 2.13.1 (using OCaml version 5.1.0)! │
└─────────────────────────────────────────────────────────────┘

Type #utop_help for help about using utop.

─( 00:00:00 )─< command 0 >──────────────────────────────────────{ counter: 0 }─
utop #
```

これでOCamlのトップレベルに入りました。OCamlの式を入力し始めることができます。例えば、`#` プロンプトで `21 * 2;;` と入力し、`Enter`キーを押してみてください。次のように表示されます:

```ocaml
# 21 * 2;;
- : int = 42
```

**おめでとうございます**! OCamlのインストールが完了しました! 🎉

UTopを終了するには、`#quit;;`(ここでの`#`はプロンプトではなく、入力する必要があります)と入力するか、`Ctrl+D`を押してください。

## コミュニティに参加する

ぜひ[OCamlコミュニティ](/community)に参加してください。[Discuss](https://discuss.ocaml.org/)や[Discord](https://discord.com/invite/cCYQbqN)で多くのコミュニティメンバーを見つけることができます。これらは何か問題があった場合に助けを求めるのに最適な場所です。
1 change: 1 addition & 0 deletions data/tutorials/getting-started/1_00_install_OCaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description: |
This page will help you install OCaml and the OCaml Platform Tools. |
These instructions work on Windows, and Unix systems like Linux, and macOS.
category: "First Steps"
language: English
---

This guide will walk you through a minimum installation of OCaml. That includes installing a package manager and [the compiler](#installation-on-unix-and-macos) itself. We'll also install some platform tools like a build system, support for your editor, and a few other important ones.
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/getting-started/1_01_a_tour_of_ocaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: A Tour of OCaml
description: >
Hop on the OCaml sightseeing bus. This absolute beginner tutorial will drive you through the marvels and wonders of OCaml. We'll have a look at the most commonly used language features.
category: "First Steps"
language: English
recommended_next_tutorials:
- "values-and-functions"
- "basic-data-types"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Your First OCaml Program
description: >
Learn how to write your very first OCaml program.
category: "First Steps"
language: English
recommended_next_tutorials:
- "values-and-functions"
- "basic-data-types"
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/getting-started/2_00_editor_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Configuring Your Editor
description: |
This page will show you how to set up your editor for OCaml.
category: "Tooling"
language: English
---
While the toplevel is great for interactively trying out the language, we will shortly need to write OCaml files in an editor. We already installed the tools required to enhance Merlin, our editor of choice with OCaml support. Merlin provides all features such as "jump to definition," "show type," and `ocaml-lsp-server`, a server that delivers those features to the editor through the LSP server.
OCaml has plugins for many editors, but the most actively maintained are for Visual Studio Code, Emacs, and Vim.
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/getting-started/2_01_toplevel.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Introduction to the OCaml Toplevel
description: |
This page will give you a brief introduction to the OCaml toplevel.
category: "Tooling"
language: English
---

An OCaml toplevel is a chat between the user and OCaml. The user writes OCaml code, and UTop evaluates it. This is why it is also called a Read-Eval-Print-Loop (REPL). Several OCaml toplevels exist, like `ocaml` and `utop`. We recommend using UTop, which is part of the [OCaml Platform](/docs/platform) toolchain.
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/getting-started/2_02_opam_switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Introduction to opam Switches
description: |
This page will give you a brief introduction to opam switches, what they're used for, and how to create them.
category: "Tooling"
language: English
---

OCaml's package manager, opam, introduces the concept of a _switch_, which is an isolated OCaml environment. These switches often cause confusion amongst OCaml newcomers, so this document aims to provide a better understanding of opam switches and their usage for managing dependencies and project-specific configurations.
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/getting-started/3_01_ocaml_on_windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: OCaml on Windows
description: >
Read about the state of OCaml on Windows and our roadmap to improve Windows support.
category: "Resources"
language: English
---

We recommend installing [opam](https://opam.ocaml.org/) for new users. Opam, the OCaml package manager, has full Windows support since version 2.2 and provides the most up-to-date OCaml environment.
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/getting-started/3_02_arm_fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Fix Homebrew Errors on Apple M1
description: |
This page will walk you through the workaround for ARM64 processors on newer Macs.
category: "Resources"
language: English
---

Since [Homebrew has changed](https://github.com/Homebrew/brew/issues/9177) the way it installs, sometimes the executable files cannot be found on macOS ARM64 M1. This might cause errors as you work through these tutorials. We want Homebrew to install ARM64 by default, so there are a few changes we need to make in order to do this.
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/getting-started/3_03_ocaml_playground.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ short_title: The OCaml Playground
description: |
This page will walk you through the OCaml Playground
category: "Resources"
language: English
---

Welcome to OCaml's in-browser playground!
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/guides/0tt_00_formatting_text.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description: >
provides pretty-printing facilities to get a fancy display for printing
routines
category: "Tutorials"
language: English
---

The `Format` module of Caml Light and OCaml's standard libraries
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/guides/0tt_01_command_line_arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Command-line Arguments
description: >
The Arg module that comes with the compiler can help you write command line interfaces
category: "Tutorials"
language: English
---

In this tutorial we learn how to read command line arguments directly, using
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/guides/0tt_02_file_manipulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: File Manipulation
description: >
A guide to basic file manipulation in OCaml with the standard library
category: "Tutorials"
language: English
---

This is a guide to basic file manipulation in OCaml using only the
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/guides/0tt_03_calling_c_libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Calling C Libraries
description: >
Cross the divide and call C code from your OCaml program
category: "Tutorials"
language: English
---

## MiniGtk
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/guides/0tt_04_calling_fortran_libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Calling Fortran Libraries
description: >
Cross the divide and call Fortran code from your OCaml program
category: "Tutorials"
language: English
---

Fortran isn't a language the many people write new code in but it still
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Using the OCaml Compiler Toolchain
description: >
An introduction to the OCaml compiler tools for building OCaml projects as well as the most common build tools such as Dune
category: "Guides"
language: English
---

This tutorial explains how to compile your OCaml programs into executable form.
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/guides/1wf_01_debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Debugging
description: >
Learn to debug OCaml programs using tracing and ocamldebug
category: "Guides"
language: English
---

This tutorial presents four techniques for debugging OCaml programs:
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/guides/1wf_02_error_handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Error Handling
description: >
Discover the different ways you can manage errors in your OCaml programs
category: "Guides"
language: English
---

In OCaml, errors can be handled in several ways. This document presents most of
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/guides/1wf_03_profiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Profiling
description: >
Understand how to profile your OCaml code to analyse its performance and produce faster programs
category: "Guides"
language: English
---

## Speed
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/guides/1wf_04_multicore_ready.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ short_title: Transitioning to Multicore with TSan
description: >
Learn to make your OCaml code multicore ready with ThreadSanitizer
category: "Guides"
language: English
---

The 5.0 release brought Multicore, `Domain`-based parallelism to the
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/guides/1wf_05_garbage_collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: How to Work with the Garbage Collector
description: >
How to use the Gc module in OCaml and how to write your own finalisers.
category: "Guides"
language: English
---

In [Understanding the Garbage Collector](/docs/garbage-collector), discussed how Garbage Collection in OCaml works.
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/guides/rs_00_guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: OCaml Programming Guidelines
description: >
Opinionated guidelines for writing OCaml code
category: "Resources"
language: English
---

This is a set of reasonable guidelines for writing OCaml
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/guides/rs_01_common_error_messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Common Error Messages
description: >
Understand the most common error messages the OCaml compiler can throw at you
category: "Resources"
language: English
---

This page gives a list of quick explanations for some error or warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Comparison of Standard Containers
description: >
Rough comparison of the different container types in OCaml
category: "Resources"
language: English
---

This is a rough comparison of the different container types
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/language/0it_00_values_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Values and Functions
description: |
Functions, values, definitions, environments, scopes, closures, and shadowing. This tutorial will help you master the fundamentals.
category: "Introduction"
language: English
prerequisite_tutorials:
- "toplevel-introduction"
- "installing-ocaml"
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/language/0it_01_basic_datatypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Basic Data Types and Pattern Matching
description: |
Predefined Types, Variants, Records, and Pattern Matching
category: "Introduction"
language: English
prerequisite_tutorials:
- "tour-of-ocaml"
- "values-and-functions"
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/language/0it_02_loops_and_recursion.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Loops and Recursions
description: >
Learn basic control-flow and recursion in OCaml
category: "Introduction"
language: English
---

As in other OCaml.org documentation, the code examples will either be something you can test or
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/language/0it_03_lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Lists
description: >
Learn about one of OCaml's must used, built-in data types
category: "Introduction"
language: English
---

A list is an ordered sequence of elements. All elements of a list in OCaml must
Expand Down
1 change: 1 addition & 0 deletions data/tutorials/language/0it_04_higher_order_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Higher Order Functions
description: >
Functions describe the world; higher-order functions take functions as parameters. Learn how to manipulate and leverage functions to write composable and reusable code.
category: "Introduction"
language: English
prerequisite_tutorials:
- "values-and-functions"
- "loops-recursion"
Expand Down
Loading