Reputation: 461
I am new to haskell, so excuse my lack of knoledge
I am trying to build a TCP server and am using the network module
import Network (listenOn, withSocketsDo, accept, PortID(..), Socket)
During compilation I get an error that the network module is not found, cabal doesnt seem to find the network module and ghc-pkg list
shows nothing
Upvotes: 2
Views: 1381
Reputation: 64740
Some terminology: What you install with cabal is a "package". What you import in code is a "module".
I am trying to build a TCP server and am using the network module
There is no "network" module in any modern Haskell package that I'm aware of. This would be your first problem.
import Network (listenOn, withSocketsDo, accept, PortID(..), Socket)
If you're new and learned of this module and functions from a resource then find something new - two years ago the network package changed and no longer exports "Network" as a module.
cabal doesnt seem to find the network module
Again cabal installs packages so you're probably meaning the network package. Cabal does know about this package:
bash-3.2$ cabal update 2>/dev/null 1>&2 && cabal info network
* network (library)
Synopsis: Low-level networking interface
...
and ghc-pkg list shows nothing
ghc-pkg is really low-level and frankly insufficient these days. It doesn't handle package environments used in new GHCs. You can, for example, setup a .ghc.environment
and use libraries listed there without ghc-pkg ever telling you those packages are installed.
For example below I install network
and have cabal write a ghc environment file, then ask ghc-pkg to list the network package (unlisted), then use the network package in GHCi (GHCi knows to read the environment file).
tommd@ovdak /tmp% cabal install --package-env . --lib network
Resolving dependencies...
Up to date
cabal install --package-env . --lib network 2.60s user 0.49s system 95% cpu 3.254 total
tommd@ovdak /tmp% ghc-pkg list network
/Users/tommd/.ghcup/ghc/8.10.1/lib/ghc-8.10.1/package.conf.d
(no packages)
tommd@ovdak /tmp% ghci
GHCi, version 8.10.1: https://www.haskell.org/ghc/ :? for help
Loaded package environment from /private/tmp/.ghc.environment.x86_64-darwin-8.10.1
package flags have changed, resetting and loading new packages...
Loaded GHCi configuration from /Users/tommd/.ghci
Prelude> import Network.Socket
Prelude Network.Socket>
Upvotes: 3
Reputation: 16645
Use hoogle to search for functions you need. It looks like you're probably looking for the network
package, which exports a few different modules (e.g. Network.Socket
)
The package name and module names are completely different things. Multiple packages may export the same module name. In general the package name never appears in your haskell code (though there is an extension for package-qualified imports)
Upvotes: 4