【发布时间】:2022-11-14 12:21:33
【问题描述】:
系统:Windows 10,Haskell 最新版本。 我正在使用堆栈包管理器。我想添加网络包 - 在 package.yaml 中添加了网络依赖项
dependencies:
- base >= 4.7 && < 5
- network
library: source-dirs: src
executables: helloworld-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- helloworld
- network
tests: helloworld-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- helloworld
- network
然后,我运行 stack build 并得到:
Installing library in D:\haskell\st\helloworld\.stack-work\install\d7cf378b\lib\x86_64-windows-ghc-9.0.2\helloworld-0.1.0.0-5CgGBgxQRsHFuCObHiusV7
Installing executable helloworld-exe in D:\haskell\st\helloworld\.stack-work\install\d7cf378b\bin
Registering library for helloworld-0.1.0.0..
Completed 2 action(s).
然后我添加 Main.hs 文件导入:
module Main where
import Lib
import Network
import System.IO
main :: IO ()
main = withSocketsDo $ do
handle <- connectTo "localhost" (PortNumber 3001)
hPutStr handle "Hello, world!"
hClose handle
但是haskell找不到依赖项:
helloworld> build (lib + exe)
Preprocessing library for helloworld-0.1.0.0..
Building library for helloworld-0.1.0.0..
[2 of 2] Compiling Lib
src\Lib.hs:5:1: error:
Could not find module `Network'
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
5 | import Network
| ^^^^^^^^^^^^^^
-- While building package helloworld-0.1.0.0 (scroll up to its section to see the error) using:
C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_3.4.1.0_ghc-9.0.2.exe --builddir=.stack-work\dist\d53b6a14 build lib:helloworld exe:helloworld-exe --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
我该如何解决?我真的需要这个包裹
【问题讨论】:
-
我想你想要
Network.Socket模块。Network模块不存在。另请注意,模块和包之间存在重要区别。
标签: haskell networking dependencies haskell-stack