LoginSignup
0
1

《プログラミングの基礎》をReScriptで読む 第一章

Last updated at Posted at 2024-04-22

《プログラミングの基礎》はとても良い本です。
サンプルプログラムをReScriptで書いて、プログラミングの基礎とReScriptを学びます。
ReScriptはmacOS Sonoma(バージョン 14.4.1)で動かしています。

第一章

《プログラミングの基礎》は使用する言語にOCamlが選ばれています。
第一章でOCamlの設定が書かれているので、真似してReScriptの設定をします。

Node.jsのインストール

ReScriptを動かすのにNode.jsとnpmが必要なのでインストールします。
Japan Node.js Assosiationからリンクをたどってインストールしました。

ReScriptのインストール

ReScript Language ManualのInstallationを参考にインストールしました。

SH
npm create rescript-app

インストールスクリプトを起動します。


SH
┌  create-rescript-app 1.6.0
│
◇  Welcome to ReScript! ─────────────────────────────────╮
│                                                        │
│  Fast, Simple, Fully Typed JavaScript from the Future  │
│  https://rescript-lang.org                             │
│                                                        │
├────────────────────────────────────────────────────────╯
│
◇  New Project ───────────────────────────────────────────╮
│                                                         │
│  Create a new ReScript 11 project with modern defaults  │
│  ("Core" standard library, JSX v4)                      │
│                                                         │
├─────────────────────────────────────────────────────────╯
│

◆  What is the name of your new ReScript project?
│  fundamentals-of-programming_

プロジェクト名を聞かれるので適切に名付けます。プロジェクト名でフォルダが作成され、その配下にファイルが配置されます。


SH
◆  Select a template
│  ○ Vite
│  ○ Next.js
│  ● Basic (Command line hello world app)
└
│
◇  Versions loaded.
│

テンプレートはBasicを選びました。


SH
◆  ReScript version?
│  ● 11.1.0-rc.8
│  ○ 11.1.0-rc.7
│  ○ 11.1.0-rc.6
│  ○ 11.1.0-rc.5
│  ○ 11.1.0-rc.4
│  ○ 11.1.0-rc.3
│  ○ 11.1.0-rc.2
│  ○ 11.1.0-rc.1
│  ○ 11.0.1
│  ○ 11.0.0
└

バージョンは一番新しいものを選びました。


SH
◆  ReScript Core version?
│  ● 1.2.0
│  ○ 1.1.0
│  ○ 1.0.0
│  ○ 0.7.0
│  ○ 0.6.0
└

ReScript Coreも一番新しいものを選びました。
ReScript v11では、大きな変更があったため、ReScript Coreが別途インストールになっているということでした。バージョンが上がると個別選択が不要になっているかも知れません。


SH
◇  Project created.
│
└  Happy hacking!

Happy hackingしていきます。


SH
cd fundamentals-of-programming
npm run res:build
node src/Demo.res.js

Hello, world!が表示されます。
srcの配下にReScriptのプログラムファイルを置いて、npm run res:buildすれば、JavaScriptにコンパイルされたファイルが作成されます。

0
1
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
0
1