インストール
linux(ubuntu LTS-22.04の例)
sudo apt update
sudo apt install build-essential curl libffi-dev libffi8ubuntu1 libgmp-dev libgmp10 libncurses-dev libncurses5 libtinfo5
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
Windows(powershellからinstall)
Set-ExecutionPolicy Bypass -Scope Process -Force;[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; try { Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing))) -ArgumentList $true } catch { Write-Error $_ }
※問題が出る場合、セキュリティソフトを一時的に停止して再実行の事
HLS,stack,MSys2をインストール
環境変数を反映する為、powershellへ入り直し
デバッガのインストール
linux
global-projectのresolverをsystem-ghcのバージョンに合わせる
※2024/03/25時点でghc=9.4.8(=lts-21.22),resolver=lts-22.13(合ってなかった)
# This is the implicit global project's config file, which is only used when
# 'stack' is run outside of a real project. Settings here do _not_ act as
# defaults for all projects. To change Stack's default settings, edit
# '/home/ueki5/.stack/config.yaml' instead.
#
# For more information about Stack's configuration, see
# http://docs.haskellstack.org/en/stable/yaml_configuration/
#
packages: []
resolver: lts-21.22
stack設定を変更(プロジェクト毎にghcをインストールせず、system-ghcを使用する)
stack config set install-ghc false --global
stack config set system-ghc true --global
デバッガをインストール
sudo apt install zlib1g-dev
stack install haskell-dap ghci-dap haskell-debug-adapter
Windows
chcp 65001
stack config set install-ghc false --global
stack config set system-ghc true --global
stack install haskell-dap ghci-dap haskell-debug-adapter --resolver lts-21.22
※注意点
・必ずchcpする事(haskellあるある)
・ghcはstackではインストールしない(必ずghcupでインストールする)
・ghcはグローバルにインストールされたものを使用
・resolverはghcupでインストールされたもの(ghcup listで確認)に合わせる
※resolverはyamlで指定した方がいいかも
以下のディレクトリをpathにいれる
C:\Users\{ユーザ名}\AppData\Roaming\local\bin
/home/{ユーザ名}/.local/bin
プロジェクト作成~実行まで(stack)
プロジェクト作成(リゾルバはインストール済みのものを指定する事)
stack new my-project --resolver lts-21.22
cd my-project
stack build
stack run
vscodeでプロジェクトを開き、以下の拡張機能をインストール
・Haskell
・Haskell GHCi Debug Adapter Phoityne
hie.yamlをプロジェクトルートに置く
cradle:
stack:
launch.jsonを作成(haskell-debug-adapter)
haskell(stack)のstartupを修正
変更前:"startup": "${workspaceFolder}/test/Spec.hs",
変更後:"startup": "${workspaceFolder}/app/Main.hs",
F5でdebug開始
※注意事項
hlsの新しいバージョンのインストールを要求されたらインストールしておく。
リゾルバで指定したghcのバージョンと食い違う場合があるが、なぜか最新をインストールしようとする。
outputで確認すると、起動されるのは適正なバージョンのようなので、使用に問題はなさそう。
モジュールの追加
インストール(モジュール名は適宜変更してください)
stack install optparse-applicative
package.yamlへエントリの追加
dependencies:
- base >= 4.7 && < 5
- optparse-applicative >= 0.17.0.0
GHCup使い方いろいろ
list available ghc/cabal versions
ghcup list
install the recommended GHC version
ghcup install ghc
install a specific GHC version
ghcup install ghc 9.2.5
set the currently "active" GHC version
ghcup set ghc 9.2.5
install cabal-install
ghcup install cabal
update ghcup itself
ghcup upgrade
uninstall stack(バージョン指定が必要)
ghcup rm stack 2.9.1
global設定 stackルートを取得
stack {path} --stack-root
⇒C:\Users\ueki0\AppData\Roaming\stack\config.yaml
C:\Users\ueki0.stack\configure.yaml
C:\Users\ueki0\AppData\Roaming\stack\config.yaml
既存のプロジェクトにリゾルバを設定
stack init --resolver {resolver}.
Cabal
プロジェクトの作成
※cabalのプロジェクトではhie.yamlは不要でした。
mkdir {hoge}
cd {hoge}
cabal init -i
Should I generate a simple project with sensible defaults? [default: y] n
What does the package build:
- Executable
- Library
- Library and Executable
Your choice? 3
What is the main module of the executable:
-
- Main.hs (does not yet exist, but will be created)
- Main.lhs (does not yet exist, but will be created)
- Other (specify)
Your choice? [default: Main.hs (does not yet exist, but will be created)] 1
Please choose version of the Cabal specification to use:
-
- 1.10 (legacy)
- 2.0 (+ support for Backpack, internal sub-libs, '^>=' operator)
- 2.2 (+ support for 'common', 'elif', redundant commas, SPDX)
- 2.4 (+ support for '**' globbing)
Your choice? [default: 1.10 (legacy)] 4
Package name? [default: start-haskell]
Package version? [default: 0.1.0.0]
Please choose a license: - GPL-2.0-only
- GPL-3.0-only
- LGPL-2.1-only
- LGPL-3.0-only
- AGPL-3.0-only
- BSD-2-Clause
-
- BSD-3-Clause
- MIT
- ISC
- MPL-2.0
- Apache-2.0
- LicenseRef-PublicDomain
- NONE
- Other (specify)
Your choice? [default: BSD-3-Clause]
Author name? [default: autotaker]
Maintainer email? [default: xxxxxx@xxxxx.com]
Project homepage URL? https://github.com/autotaker/start-haskell
Project synopsis? my favorite cabal project example
Project category:
-
- (none)
- Codec
- Concurrency
- Control
- Data
- Database
- Development
- Distribution
- Game
- Graphics
- Language
- Math
- Network
- Sound
- System
- Testing
- Text
- Web
- Other (specify)
Your choice? [default: (none)]
Application (Main.hs) directory:
-
- (none)
- src-exe
- app
- Other (specify)
Your choice? [default: (none)] 3
Library source directory:
-
- (none)
- src
- lib
- src-lib
- Other (specify)
Your choice? [default: (none)] 2
Should I generate a test suite for the library? [default: y] y
Test directory:
-
- test
- Other (specify)
Your choice? [default: test] 1
What base language is the package written in:
-
- Haskell2010
- Haskell98
- Other (specify)
Your choice? [default: Haskell2010]
Add informative comments to each field in the cabal file (y/n)? [default: n] n
Guessing dependencies...
Generating LICENSE...
Generating Setup.hs...
Generating CHANGELOG.md...
Generating src/MyLib.hs...
Generating app/Main.hs...
Generating test/MyLibTest.hs...
Generating start-haskell.cabal...
You may want to edit the .cabal file and add a Description field.
Cabalプロジェクトでデバッグ
launch.jsonの作成
launch.jsonの修正(haskell(cabal))
cabal replから--repl-no-load
の指定を削除
その他
stack設定
# This is the implicit global project's config file, which is only used when
# 'stack' is run outside of a real project. Settings here do _not_ act as
# defaults for all projects. To change Stack's default settings, edit
# '/home/ueki5/.stack/config.yaml' instead.
#
# For more information about Stack's configuration, see
# http://docs.haskellstack.org/en/stable/yaml_configuration/
#
packages: []
resolver: lts-21.22
# This file contains default non-project-specific settings for Stack, used
# in all projects. For more information about Stack's configuration, see
# http://docs.haskellstack.org/en/stable/yaml_configuration/
# The following parameters are used by 'stack new' to automatically fill fields
# in the Cabal file. We recommend uncommenting them and filling them out if
# you intend to use 'stack new'.
# See https://docs.haskellstack.org/en/stable/yaml_configuration/#templates
templates:
params:
# author-name:
# author-email:
# copyright:
# github-username:
# The following parameter specifies Stack's output styles; STYLES is a
# colon-delimited sequence of key=value, where 'key' is a style name and
# 'value' is a semicolon-delimited list of 'ANSI' SGR (Select Graphic
# Rendition) control codes (in decimal). Use 'stack ls stack-colors --basic'
# to see the current sequence.
# stack-colors: STYLES
install-ghc: false
system-ghc: true