Haskell - 小煩惱
vscode-haskell
Toolchain 選擇
在 .vscode/settings.json 中使用 haskell.toolchain 選擇指定版本。
例
{
"haskell.toolchain": {
"hls": "2.2.0.0",
"cabal": "3.10.1.0",
"stack": "2.11.1"
}
}
formatter 選擇
floskell, config
LSP - Language Server Protocol
- Client: vscode-haskell ( vscode-languageclient )
- Server: haskell-language-server ( lsp, hls-graph, ghcide, hls-plugin, hie-bios, hiedb , GHC, ... )
遇到問題,不妨重啟試試。
- hie-bios 目前優先設定為隱式發現。
- Multi Cradle: No prefixes matched, 先不關注
- Loading the module 'foo.hs' failed, 聽從提示
- !!MISSING: command!!, 等等看
GHCi
Multi line
GHCi 里使用 :{ ... :}或使用 :set +m.
Loading a multi-module program
在 .hs 所在目錄,GHCi 里使用 :load Main,會根據 impdecls 查找 import 項。
GHC Package environments
A package environment file is a file that tells ghc precisely which packages should be visible.
控制某包是否可見,如某包不可見,GHC/GHCi 處理時會顯示類似于It is a member of the hidden package 'base-4.17.2.0', 需要設置為可見。
-hide-all-packages, This is a good way to insulate your program from differences in the globally exposed packages, and being explicit about package dependencies is a Good Thing.Cabal always passes the
-hide-all-packagesflag to GHC, for exactly this reason.
GHC/GHCi 會默認加載當前目錄(及父目錄)下的 package environment file, 其次全局;選項-package-env <file>指定加載.
Cabal ( cabal-install )
proj.cabal
先關注 other-modules 和 build-depends 項,其他項有更多需求再關注。
other-modules
For an executable, other modules included in the executable should be listed in the
other-modulesfield.
build-depends
Instead, you add the package you want to use to the
build-dependssection of the.cabalfile of your package.Cabal will take care of fetching and building the dependency as needed when you run
cabal build,cabal run, or other similar commands.
Cabal 項目中,在 build-depends添加依賴庫名稱,Cabal 會處理的。
Adding libraries to GHC package environments
cabal install --lib, 默認為全局,%APPDATA%/ghc/$ARCH-$OS-$GHCVER/environments/default.
cabal install --package-env 配合使用,確定使用哪個.
更多
- 2022 State of Haskell Survey Results - <https://taylor.fausak.me/2022/11/18/haskell-survey-results/>
- 「Haskell に IDE はないのか?──獨斷と偏見による Haskell の IDE 十年史」 - <https://zenn.dev/konn/articles/1a60baba9848a1>
-
Mitchell, N., Kiefer, M., Iborra, P., Lau, L., Duggal, Z., Siebenhandl, H., Sanchez, J. N., Pickering, M., & Zimmerman, A. Building an Integrated Development Environment (IDE) on top of a Build System: The tale of a Haskell IDE. Proceedings of the 32nd Symposium on Implementation and Application of Functional Languages, 1–10. 2020. https://doi.org/10.1145/3462172.3462180
- https://cabal.readthedocs.io/en/3.10/developing-packages.html#modules-included-in-the-package
- https://downloads.haskell.org/ghc/latest/docs/users_guide/packages.html#package-environments
- https://cabal.readthedocs.io/en/3.10/cabal-commands.html#cabal-install
- Separate cabal install --lib into own command (cabal env) - <https://github.com/haskell/cabal/issues/6481>
- Improve the error message for unknown modules - <https://github.com/haskell/haskell-language-server/issues/3695>
- 2021 How to get VSCode to recognize a dependency - <https://github.com/tomjaguarpaw/tilapia/issues/93>
- HLS 2.3.0.0 release possibly borked on Windows - <https://github.com/haskell/haskell-language-server/issues/3822>

浙公網安備 33010602011771號