haskell,错误':set -package unordered-containers',ghci

问题描述 投票:0回答:1

我刚刚开始使用 haskell..尝试使用键值对..

在 reddit 上看到这个例子

https://www.reddit.com/r/haskellquestions/comments/2xn9y2/whats_the_equivalent_of_a_python_dictionary_in/

λ> import qualified Data.HashMap.Strict as M
λ> let d = M.fromList [("a", 10.33), ("c", 20.23), ("d", 100.33)]
λ> d
fromList [("d",100.33),("a",10.33),("c",20.23)]
λ> M.lookup "c" d
Just 20.23
λ> M.insert "z" 77 d
fromList [("z",77.0),("d",100.33),("a",10.33),("c",20.23)]

当我尝试运行它时出现错误 ':set -package 无序容器'

当我这样做时,代码就会运行..

我不清楚的是以下内容

  1. 这是什么意思?

  2. 这是默认设置吗?如果不是我应该将其设为默认吗?

  3. 最后,如果我在 haskell 脚本中重复该示例,我需要做什么才能获得相同的设置?

我在google上搜索发现它是这个包的一部分 https://hackage.haskell.org/package/unordered-containers-0.2.19.1/docs/Data-HashMap-Strict.html

当我使用堆栈创建一个新项目并添加依赖项时

  • 无序容器-0.2.19.1

并运行它,它给出了这个错误

/Users/air/haskell/thinkingFunctionally/myproj/src/Lib.hs:4:1: error:
    Could not find module ‘Data.HashMap.Strict’
    Perhaps you meant
      Data.Map.Strict (needs flag -package-id containers-0.6.7)
      Data.IntMap.Strict (needs flag -package-id containers-0.6.7)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
4 | import qualified Data.HashMap.Strict as M
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Error: [S-7282]
       Stack failed to execute the build plan.

       While executing the build plan, Stack encountered the error:

       [S-7011]
       While building package myproj-0.1.0.0 (scroll up to its section to see the error) using:
       /Users/air/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_6HauvNHV_3.10.1.0_ghc-9.6.3 --verbose=1 --builddir=.stack-work/dist/x86_64-osx/ghc-9.6.3 build lib:myproj exe:myproj-exe --ghc-options " -fdiagnostics-color=always"
       Process exited with code: ExitFailure 1

我的 .cabal 文件如下


source-repository head
  type: git
  location: https://github.com/githubuser/myproj

library
  exposed-modules:
      Lib
  other-modules:
      Paths_myproj
  autogen-modules:
      Paths_myproj
  hs-source-dirs:
      src
  ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints
  build-depends:
      base >=4.7 && <5
  default-language: Haskell2010

executable myproj-exe
  main-is: Main.hs
  other-modules:
      Paths_myproj
  autogen-modules:
      Paths_myproj
  hs-source-dirs:
      app
  ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , myproj
  default-language: Haskell2010

test-suite myproj-test
  type: exitcode-stdio-1.0
  main-is: Spec.hs
  other-modules:
      Paths_myproj
  autogen-modules:
      Paths_myproj
  hs-source-dirs:
      test
  ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , myproj
  default-language: Haskell2010

这是我的第一篇文章..所以我希望我在这里有意义

提前感谢您的帮助..

haskell ghci unordered-containers
1个回答
0
投票

unordered-comtainers
添加到
build-depedends

library
  # …
  build-depends:
      base >=4.7 && <5
      unordered-containers >=0.2.19.1
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.