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-packages
flag 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-modules
field.
build-depends
Instead, you add the package you want to use to the
build-depends
section of the.cabal
file 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>