【问题标题】:Could not find module `Network' Haskell Stack找不到模块 `Network\' Haskell Stack
【发布时间】: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


【解决方案1】:

我想您正在学习您在网络上或某些书中找到的教程(我知道 Simon Marlow 书中关于套接字编程的代码已经过时)。请注意,网络库从 3.0 版开始发生了显着变化,因为它不再公开网络模块。 您可以尝试按照本教程了解如何使用此库

https://dev.to/leandronsp/a-crud-journey-in-haskell-part-ii-socket-programming-2po1

干杯,

【讨论】:

    猜你喜欢
    • 2017-07-27
    • 2013-08-05
    • 1970-01-01
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多