I am experimenting with Conduit Network and I cannot compile this code because it is cannot find the data constructor: HostAny
conduit-extra is installed so I am very puzzled why it cannot find it?
{-# LANGUAGE ScopedTypeVariables #-}
import Data.Conduit
import Data.Conduit.Network
serverApp :: AppData -> IO ()
serverApp d = do appSource d $$ appSink d
main :: IO()
main = runTCPServer (serverSettings 8900 HostAny) serverApp
Here's the GHC error:
pez@devbox:~/dev$ runhaskell server.hs
server.hs:10:42: Not in scope: data constructor `HostAny'
If you look at the documentation for conduit-extras
, you'll see
data HostPreference
Which host to bind.
Note: The IsString instance recognizes the following special values:
* means HostAny *4 means HostIPv4 !4 means HostIPv4Only *6 means HostIPv6 !6 means HostIPv6Only
Which tells me that you should be using the extension OverloadedStrings
and then you can just write your code as
main = runTCPServer (serverSettings 8900 "*") serverApp
Although I have to say that is a strange API this library has chosen. I personally would much rather have the ability to use IsString
or an explicit constructor in cases where I don't want to use OverloadedStrings
for whatever reason.