2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Raspberry Pi に OCaml をインストールする方法

Last updated at Posted at 2025-08-22

Raspberry Pi で関数型言語 OCaml を使いたい方向けに、インストール手順を紹介します。

対象環境

  • Raspberry Pi 4 (他モデルでも問題なし)
  • Raspberry Pi OS Bookworm(最新版)
  • ターミナル操作ができること(SSH または HDMI 接続)
  • Raspberry Pi のセットアップが完了していること

手順の全体像

零. OCaml の紹介

  1. パッケージのインストール
  2. 動作確認
  3. 簡単なハンズオン
  4. まとめ

0. OCaml の紹介

OCaml は、関数型プログラミング を中心にしながら、命令型 や オブジェクト指向 の特徴も取り入れた多機能なプログラミング言語です。
研究・産業の両分野で利用されており、堅牢なソフトウェア開発に向いています。

1. パッケージのインストール

sudo apt update
sudo apt install ocaml ocaml-native-compilers camlp4-extra opam -y

バージョンを確認する

user@raspberrypi:~ $ ocaml -version
The OCaml toplevel, version 4.13.1

2. 動作確認

ocamlのコマンドで OCaml の REPL(対話環境)を起動できます。

user@raspberrypi:~ $ ocaml
        OCaml version 4.13.1
# 
# print_endline "Hello, OCaml on Raspberry Pi!";;
Hello, OCaml on Raspberry Pi!
- : unit = ()
# 

3. 簡単なハンズオン

四則演算

# 2 + 3 * 4;;
- : int = 14

変数の定義

# let pi = 3.1415;;
val pi : float = 3.1415

関数定義と呼び出し

# let square x = x * x;;
val square : int -> int = <fun>
# square 5;;
- : int = 25

リストとパターンマッチ

# let numbers = [1; 2; 3; 4];;
val numbers : int list = [1; 2; 3; 4]
# match numbers with
  | [] -> "empty"
  | h :: t -> "head is " ^ string_of_int h;;
- : string = "head is 1"

4. まとめ

Raspberry Pi に OCaml をインストールしました。
これをきっかけに、関数型プログラミングの世界を楽しんでみてください。

よろしければ、いいね、ストック、コメントいただけますと幸いです。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?