Open15

Haskell 何もわからないけど Web API が作りたい

kaito2kaito2

とりあえずビルドしようと思ったらエラー

stack build
WARNING: Ignoring primitive's bounds on base (>=4.8 && <4.17); using base-4.17.0.0.
Reason: trusting snapshot over Cabal file dependency information.
WARNING: Ignoring aeson's bounds on ghc-prim (>=0.5.0.0 && <0.9); using ghc-prim-0.9.0.
Reason: trusting snapshot over Cabal file dependency information.
WARNING: Ignoring aeson's bounds on template-haskell (>=2.11.0.0 && <2.19); using template-haskell-2.19.0.0.
Reason: trusting snapshot over Cabal file dependency information.
WARNING: Ignoring http-api-data's bounds on base (>=4.7 && <4.17); using base-4.17.0.0.
Reason: trusting snapshot over Cabal file dependency information.
WARNING: Ignoring memory's bounds on ghc-prim (<0.9); using ghc-prim-0.9.0.
Reason: trusting snapshot over Cabal file dependency information.

Error: [S-4804]
       Stack failed to construct a build plan.

       While constructing the build plan, Stack encountered the following errors:

       In the dependencies for cabal-doctest-1.0.9:
           Cabal must match >=1.10 && <3.10, but the Stack configuration has no specified version (latest matching version is 3.8.1.0)
       needed due to first-servant-project-0.1.0.0 -> cabal-doctest-1.0.9

       In the dependencies for wai-logger-2.4.0:
           Cabal needed, but the Stack configuration has no specified version (latest matching version is 3.8.1.0)
       needed due to first-servant-project-0.1.0.0 -> wai-logger-2.4.0
kaito2kaito2

https://stackoverflow.com/questions/61327636/category-extras-needed-but-the-stack-configuration-has-no-specified-version

stack was built explicitly because the authors believed that resolving package dependencies automatically was a big mistake. That is the true answer to "why". But there are workarounds; hopefully some folks will write them up some. Or you could switch to cabal, which embraces dependency solving; this introduces problems of its own. It's a tradeoff.

Naruhodo?

kaito2kaito2

stack としてインストールするのね…

$ asdf plugin add stack
$ asdf list all stack
2.5.1
2.7.1
2.7.3
2.7.5
2.9.1
2.9.3
$ asdf install stack 2.9.3
$ asdf global stack 2.9.3
$ stack --version
fVersion 2.9.3, Git revision d0e984f00034552aac7c67675d49ef0807c10c7b (dirty) (112 commits) aarch64
Compiled with:
...
kaito2kaito2

ちがった

$ asdf plugin add cabal https://github.com/sestrella/asdf-ghcup.git
$ asdf list all cabal
2.4.1.0
3.0.0.0
3.2.0.0
3.4.0.0
3.4.1.0
3.6.0.0
3.6.2.0
3.8.1.0
$ asdf install cabal 3.8.1.0
$ asdf global cabal 3.8.1.0
$ cabal --version
cabal-install version 3.8.1.0
compiled using version 3.8.1.0 of the Cabal library
kaito2kaito2
cabal new-build tutorial
Config file path source is default config file.
Config file not found: /Users/kaito2/.cabal/config
Writing default configuration to /Users/kaito2/.cabal/config
Error: cabal: The program 'ghc' version >=7.0.1 is required but it could not
be found.
asdf plugin add haskell
asdf install haskell 9.4.4
kaito2kaito2

ローカル環境は諦めておとなしく Docker コンテナに閉じこもることに…

$ docker run -it --volume $(pwd):/app -p 8080:8080 haskell:9.4 bash
# cd /app
# stack new myproj servant
...
# cd myproj
# stack --install-ghc build
# stack exec myproj-exe
$ curl localhost:8080/users
[{"userId":1,"userFirstName":"Isaac","userLastName":"Newton"},{"userId":2,"userFirstName":"Albert","userLastName":"Einstein"}]