How can I load a project into VSC

Hello, this is my first time posting in this wonderful community.

I would like to import the following project into my VSC. This is the structure of the project:

Screenshot 2022-12-12 at 18.22.40

The problem is, the system doesn’t find Board nor Ploy modules, and not even System.Random. How can I configure my setup to solve the problem ?

package.yaml
name:                ploy
version:             1.0.0.0
author:              "Simon Schwan"
maintainer:          "s.schwan@tu-berlin.de"
copyright:           "2022 TU Berlin - Software and Embedded Systems Engineering (SESE)"

dependencies:
- base >= 4.7 && < 5
- split
- random

ghc-options:
- -Wall
- -Wcompat
- -Widentities
- -Wincomplete-record-updates
- -Wmissing-home-modules
- -Wpartial-fields
- -Wredundant-constraints
- -Wno-missing-export-lists
- -fno-warn-missing-signatures
- -fno-warn-name-shadowing
- -fno-warn-incomplete-patterns

library:
  source-dirs: src

executables:
  ploy:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - ploy

tests:
  units:
    main:                Spec.hs
    source-dirs:         test
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - ploy
    - hspec
  validate:
    main:               Spec.hs
    source-dirs:        validate
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - ploy
    - hspec

Can you describe what you mean when you say “the system doesn’t recognize the modules”? Are you entering a repl with stack ghci? Or do you mean the Haskell Language Server?

Sorry, I was really imprecise. In VSC, I have the following error message when I use Run Script extension while at the Main.hs file.

I can’t import System.Random in ghci.

I have installed ghcup, cabal, stack.

Does stack ghci entered in the shell (in the project directory) work?

Um… I am unaware of such extension, at least with haskell. Tipically, you run your program with stack run ploy. Any way for the sake of debugging, in the project folder:

  • does stack build work without failure?
  • does stack ghci enter in the shell?
  • within the ghci session, can you run import System.Random?
  • does stack run ploy do something?

All of the above should work, if it doesn’t, feel free to copy-paste the error messages here :wink:

1 Like

Thank you for all the suggestions !

This is the message I get.

Exception while reading snapshot from https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/30.yaml:
HttpExceptionRequest Request {
  host                 = "raw.githubusercontent.com"
  port                 = 443
  secure               = True
  requestHeaders       = [("User-Agent","Haskell pantry package")]
  path                 = "/commercialhaskell/stackage-snapshots/master/lts/19/30.yaml"
  queryString          = ""
  method               = "GET"
  proxy                = Nothing
  rawBody              = False
  redirectCount        = 10
  responseTimeout      = ResponseTimeoutDefault
  requestVersion       = HTTP/1.1
  proxySecureMode      = ProxySecureWithConnect
}
 (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [AI_ADDRCONFIG], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just "raw.githubusercontent.com", service name: Just "443"): does not exist (nodename nor servname provided, or not known))

If I write ghci (without prepending stack) works.

These are the error messages I get, and thank you for your time.

[2 of 2] Compiling StackSetupShim   ( /Users/detach/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /Users/detach/.stack/setup-exe-src/setup-shim-mPHDZzAJ.o )

<no location info>: error:
    Warning: Couldn't figure out LLVM version!
             Make sure you have installed LLVM between [9 and 13)
ghc-9.0.2: could not execute: opt

--  While building simple Setup.hs (scroll up to its section to see the error) using:
      /Users/detach/.ghcup/ghc/9.0.2/bin/ghc -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is StackSetupShim.mainOverride -package Cabal-3.4.1.0 /Users/detach/.stack/setup-exe-src/setup-mPHDZzAJ.hs /Users/detach/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -o /Users/detach/.stack/setup-exe-cache/aarch64-osx/tmp-Cabal-simple_mPHDZzAJ_3.4.1.0_ghc-9.0.2
    Process exited with code: ExitFailure 1

Linking /Users/detach/.stack/setup-exe-cache/aarch64-osx/tmp-Cabal-simple_mPHDZzAJ_3.4.1.0_ghc-9.0.2 ...
Undefined symbols for architecture arm64:
  "_Cabalzm3zi6zi3zi0_DistributionziSimple_defaultMainWithHooks_closure", referenced from:
      _Lc3hG_info in setup-shim-mPHDZzAJ.o
      _Lu3iz_srt in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimple_defaultMain_closure", referenced from:
      _Main_main_closure in setup-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimple_simpleUserHooks_closure", referenced from:
      _Lc3bc_info in setup-shim-mPHDZzAJ.o
      _Lc3bq_info in setup-shim-mPHDZzAJ.o
      _Ls3b6_info in setup-shim-mPHDZzAJ.o
      _Lu3ed_srt in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimpleziBuild_initialBuildSteps_closure", referenced from:
      _Lc3bv_info in setup-shim-mPHDZzAJ.o
      _Lu3ec_srt in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimpleziFlag_fromFlag_closure", referenced from:
      _Ls3ad_info in setup-shim-mPHDZzAJ.o
      _Ls3a0_info in setup-shim-mPHDZzAJ.o
      _Lu3e9_srt in setup-shim-mPHDZzAJ.o
      _Lu3eb_srt in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimpleziSetup_replDistPref_closure", referenced from:
      _Ls39Z_info in setup-shim-mPHDZzAJ.o
      _Lu3e8_srt in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimpleziSetup_replVerbosity_closure", referenced from:
      _Ls3ac_info in setup-shim-mPHDZzAJ.o
      _Lu3ea_srt in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimpleziUserHooks_UserHooks_con_info", referenced from:
      _Lc3hP_info in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimpleziUserHooks_replHook_closure", referenced from:
      _Lc3bc_info in setup-shim-mPHDZzAJ.o
      _Lc3bq_info in setup-shim-mPHDZzAJ.o
      _Lu3ed_srt in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziTypesziHookedBuildInfo_emptyHookedBuildInfo_closure", referenced from:
      _Ls3b0_info in setup-shim-mPHDZzAJ.o
      _Lu3iv_srt in setup-shim-mPHDZzAJ.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)

--  While building simple Setup.hs (scroll up to its section to see the error) using:
      /Users/detach/.ghcup/ghc/9.0.2/bin/ghc -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is StackSetupShim.mainOverride -package Cabal-3.4.1.0 /Users/detach/.stack/setup-exe-src/setup-mPHDZzAJ.hs /Users/detach/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -o /Users/detach/.stack/setup-exe-cache/aarch64-osx/tmp-Cabal-simple_mPHDZzAJ_3.4.1.0_ghc-9.0.2
    Process exited with code: ExitFailure 1

I am using macOS Ventura, by the way. And GHC 9.2.5.

@unlocked2412 Just one more question. Did you install stack via ghcup or using stack’s installation script? From the output of your commands I think the former, which is the correct way.

  • If you installed stack via its own script, then I’d suggest to remove it and use ghcup. Also be sure you use stack-2.9.1.

In case you installed stack with ghcup continue reading:

I see many problems in your current status:

  • First, It seems like your project’s stack.yaml uses lts-19.30 which depends on ghc-9.0.2 not ghc-9.2.5 as you claim (please check stackage for this).
  • Therefore stack build is trying to instal ghc-9.0.2 (via ghcup) which If I am not mistaken needs LLVM on macOS due to new arquitecture.
  • Apparently, you don’t have LLVM installed, therefore the error when calling stack build.
  • The error when running stack ghci is new to me but I’d guess it is related with the previous one, somehow.
  • The command ghci runs (when called out of stack) so I am asuming that your ghc is ok, and you are using version 9.2.5. It is important to use such a version on macOS Ventura because 9.2.4 is broken in such system
  • Now, hls is not supported (yet) for ghc-9.2.5 so even if stack were working, vscode wouldn’t be responsive.

How do you escape this dependency hell? well… I don’t have a clear solution. I’d try installing ghc-9.4.2 and cabal-3.8.1.0. Then modify your stack.yaml in the project so the resolver is resolver: nightly-2020-12-12. If stack complains, try building with cabal.

also, notice that ghci by itself can’t use System.Random or modules in external packages. You need to use cabal repl or stack repl or stack ghci within a project folder to get access to packages in that project.

All of the above is writen from memory so double check with others

regards

Thank you for your help.

Exactly. That’s right.

I had done this steps. Now I get with stack build:

Error message
Linking /Users/detach/.stack/setup-exe-cache/aarch64-osx/tmp-Cabal-simple_mPHDZzAJ_3.4.1.0_ghc-9.0.2 ...
Undefined symbols for architecture arm64:
  "_Cabalzm3zi6zi3zi0_DistributionziSimple_defaultMainWithHooks_closure", referenced from:
      _Lc3hG_info in setup-shim-mPHDZzAJ.o
      _Lu3iz_srt in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimple_defaultMain_closure", referenced from:
      _Main_main_closure in setup-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimple_simpleUserHooks_closure", referenced from:
      _Lc3bc_info in setup-shim-mPHDZzAJ.o
      _Lc3bq_info in setup-shim-mPHDZzAJ.o
      _Ls3b6_info in setup-shim-mPHDZzAJ.o
      _Lu3ed_srt in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimpleziBuild_initialBuildSteps_closure", referenced from:
      _Lc3bv_info in setup-shim-mPHDZzAJ.o
      _Lu3ec_srt in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimpleziFlag_fromFlag_closure", referenced from:
      _Ls3ad_info in setup-shim-mPHDZzAJ.o
      _Ls3a0_info in setup-shim-mPHDZzAJ.o
      _Lu3e9_srt in setup-shim-mPHDZzAJ.o
      _Lu3eb_srt in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimpleziSetup_replDistPref_closure", referenced from:
      _Ls39Z_info in setup-shim-mPHDZzAJ.o
      _Lu3e8_srt in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimpleziSetup_replVerbosity_closure", referenced from:
      _Ls3ac_info in setup-shim-mPHDZzAJ.o
      _Lu3ea_srt in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimpleziUserHooks_UserHooks_con_info", referenced from:
      _Lc3hP_info in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziSimpleziUserHooks_replHook_closure", referenced from:
      _Lc3bc_info in setup-shim-mPHDZzAJ.o
      _Lc3bq_info in setup-shim-mPHDZzAJ.o
      _Lu3ed_srt in setup-shim-mPHDZzAJ.o
  "_Cabalzm3zi6zi3zi0_DistributionziTypesziHookedBuildInfo_emptyHookedBuildInfo_closure", referenced from:
      _Ls3b0_info in setup-shim-mPHDZzAJ.o
      _Lu3iv_srt in setup-shim-mPHDZzAJ.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)

--  While building simple Setup.hs (scroll up to its section to see the error) using:
      /Users/detach/.ghcup/ghc/9.0.2/bin/ghc -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is StackSetupShim.mainOverride -package Cabal-3.4.1.0 /Users/detach/.stack/setup-exe-src/setup-mPHDZzAJ.hs /Users/detach/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -o /Users/detach/.stack/setup-exe-cache/aarch64-osx/tmp-Cabal-simple_mPHDZzAJ_3.4.1.0_ghc-9.0.2
    Process exited with code: ExitFailure 1

When I build with cabal, it says:

Resolving dependencies...
Build profile: -w ghc-9.2.5 -O1

but I installed ghc-9.4.2. That’s weird.

you’ve installed ghc-9.4.2, but have you set it as the one in the path? Notice that ghcup can install different versions of the compiler you have to tell it to set the one you want. You should see it with a double check in ghcup tui (in the image below 9.2.4 and 8.10.7 are installed but only the latter is set). Select the ghc version and press s. In case the tui doesn’t work in macOS ghcup set ghc 9.4.2

image

1 Like

um… now, looking closer to the error it seems like you are missing a C dependency, but at this point I get a little bit lost, lets wait it you can build with cabal

Thank you so much. These are now my settings:

I’ll continue investigating and will report back.

@Lsmor I solved the issue !!

I used this:

but resolver: 9.4.2.

Additionally, in extra-deps I used:

extra-deps: [
    splitmix-0.1.0.4@sha256:804e2574bc7e32d08cbab91e47ee6287b4df7d50851d73f9e778f94a9a7814c7,
    random-1.2.1.1@sha256:dea1f11e5569332dc6c8efaad1cb301016a5587b6754943a49f9de08ae0e56d9,
    split-0.2.3.5@sha256:f472fa7019647cacac3267742a6f7ac0a5c816f9890e80e4b826cd937436de87
]

in stack.yaml.

I cannot thank you enough. It’s amazing how much you have helped me.

Can I ask you two questions ? Is it possible to use, as extra-deps, the names of the libraries instead the specific version and that long encoded string ?

The second one is:

Why does System.Random gives so much problems ? I’ve always had troubles importing it. Does it have some particularity ?

indeed!! I turns out resolver: nightly-2020-12-12 is for ghc-9.4.3, not ghc-9.4.2 :sweat_smile:

You can do it following the example from documentation, but I think there is a sweeter solution by simply overriding the compiler. You need to do this because if you specify resolver: ghc-9.4.2 you’ll get an snapshot with only the compiler but not other packages (as random or split). So your files will look like

  • stack.yaml
resolver: lts-20.4  # Inherits GHC version and package set
compiler: ghc-9.4.2 # Overwrites GHC version in the resolver
  • package.yaml
dependencies:
- base >= 4.7 && < 5
- split
- random

...

So you have the best of both worlds: A compiler working in macOS out of the box and a curated set of packages via lts-20.4,

Didn’t have the same experience. random package has (not-so-)recently had a major update, which may have cause dependency incompatibilities. Maybe your are experiencing such a thing.

Also is very common to think about haskell as if the same as about python, for example: I can type pip install numpy and then import numpy as np within any python repl in my system. This is not the case for haskell, If you run ghci or stack repl or cabal repl, in general you don’t have access to packages other than base, you must run stack repl or cabal repl within a project which has random as a dependency, which is very different from the python world

1 Like

This is amazing ! I didn’t have to specify extra-deps and compiled anyway !

But I don’t think I understood your explanation. What’s the difference between resolver and compiler options and what do you mean by snapshot ? An image file of the compiler build ?

Sorry, I didn’t clarify myself sufficiently. Now, I realised that I have had problem also with Data.List.Split. Every time I need a package outside of base.

So, my question would be: what’s a good way to quickly test code without creating a project. Sometimes, I want to test a couple of functions in a script and I use the command runhaskell to run the script file. But, whenever I need an external module, I have that same problem.

stack works by specifying a specific set of packages in the stack.yaml file. This set of packages is named resolver or snapshot. Commonly, those are the ones defined in a lts snapshot in www.stackage.org, but they can be others.

a few examples:

-- stack.yaml
-- This will use ghc-9.2.5 and package versions in such a snapshot
resolver: lts-20.4 

-- stack.yaml
-- This will use ghc-9.0.2 and package versions in such a stackage snapshot
-- plus and extra dependency from hackage
resolver: lts-19.33
extra-deps:
 - acme-1.3

-- stack.yaml
-- this will use ghc-9.4.2 an only the base package include in it
resolver: ghc-9.4.2  

-- stack.yaml
-- this will use ghc-9.4.2 an its base package plus a package pulled from github
resolver: ghc-9.4.2  
extra-deps:
- git: git@github.someuser/someapackage.git
  commit: 6a86ee32e5b869a877151f74064572225e1a0398

As you can see there are many ways you can specify the set of packages you want to use. They are specify in the docs

In your case, you want to use a set of packages defined in lts-20.4 but using a different version of the compiler therefore:

-- stack.yaml
resolver: lts-20.4  # the snapshot version
compiler: ghc-9.4.2 # the GHC version

In general, you’d have a better experience if you create a project, since within the project folder stack repl will have access to all dependencies. Anyway, if you run stack repl it will open a ghci session only with base. Within ghci prompt you can run

ghci> :set -package random
ghci> import System.Random

But I don’t know if it works if you haven’t build the random package previously, for example. So maybe you have to run something like

# not a tested solution, and this doesn't work in my machine. But I am a cabal user
stack repl --resolver lts-20.4 --with-ghc 9.4.2 --package random
2 Likes

Amazing. I can’t thank you enough for all of the explanations.

3 Likes