概要
Idris2の依存型を試してみたいので、環境構築を行います。
本記事ではあくまで環境構築のみ行い、依存型に関する記載はないのであしからず。
インストール
MacOSではbrewでインストール可能です。
brew install idris2
Idris2のパッケージマネージャーであるpackをインストールします。
公式に書いてある以下のコマンドを実行してください。
bash -c "$(curl -fsSL https://raw.githubusercontent.com/stefan-hoeck/idris2-pack/main/install.bash)"
Language Serverをインストールします (参考)
pack install-app idris2-lsp
環境構築
vim
プラグインは以下のものを利用します。
キーマップは以下のようにします。
local map = vim.keymap.set
local opts = {buffer = bufnr, silent = true}
map("n", "<C-t>p", "<cmd>!idris2 --exec main %<CR>", opts)
map("n", "<C-t>b", "<cmd>!idris2 % -o %:r<CR>", opts)
map("n", "<C-t>c", "<cmd>!idris2 --check %<CR>", opts)
map("n", "<C-t>P", "<cmd>!./build/exec/%:r<CR>", opts)
VSCode
拡張機能は以下のものをインストールします。
- https://marketplace.visualstudio.com/items?itemName=bamboo.idris2-lsp
- https://marketplace.visualstudio.com/items?itemName=j-nava.idris2-language-support
VSCode上で動作するIdris2のデバッガーは存在しないようなので、以下のタスクを作成して実行できるようにします。
以下のファイルを作成してプロジェクトの.vscode/task.jsonに配置してください。
Cmd + Shift + b で各タスクを呼び出せます。
task.json
{
"version": "2.0.0",
"tasks": [
{
"label": "idris2.check",
"type": "shell",
"command": "idris2",
"args": [
"--check",
"${file}"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "shared"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "idris2.run",
"type": "shell",
"command": "idris2",
"args": [
"--exec",
"main",
"${file}"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "shared"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "idris2.build",
"type": "shell",
"command": "idris2",
"args": [
"--build"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "shared"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
ターミナル上での実行
ターミナル上で実行する場合は、以下の様にします。
idris2 --exec 関数名 ファイルパス
以下のファイルの場合は、idris2 --exec main hello.idrとなります。
hello.idr
module Main
main : IO ()
main = putStrLn "Hello, World"