10

Why is such simple code not working?

import Network.HTTP.Conduit
import qualified Data.ByteString.Lazy as L

main :: IO ()
main = simpleHttp "http://www.dir.bg/" >>= L.putStr

It results in the following error:

TestConduit.exe: InternalIOException getAddrInfo: does not exist (error 10093)

Alex
  • 8,093
  • 6
  • 49
  • 79
The_Ghost
  • 2,070
  • 15
  • 26

1 Answers1

15

You have to use withSocketsDo to initialize sockets. Like this:

import Network.HTTP.Conduit
import qualified Data.ByteString.Lazy as L
import Network (withSocketsDo)

main :: IO ()
main = withSocketsDo
      $ simpleHttp "http://www.dir.bg/" >>= L.putStr
Alex
  • 8,093
  • 6
  • 49
  • 79
The_Ghost
  • 2,070
  • 15
  • 26
  • 3
    Actually, you should always use `withSocketsDo`, if on Windows or not. Then you'll never have this problem. :-) – Waldheinz Oct 03 '13 at 14:36
  • I'm curious why this initialization is not happening behind the curtains or on-demand automatically? – The_Ghost Oct 03 '13 at 18:00
  • 3
    @The_Ghost or designed so that well-typed code doesn't blow up, right? There's really no excuse for this kind of thing in haskell. – jberryman Oct 03 '13 at 18:31
  • Yes, but we could put a lot of other stuff. We could brake withSocketsDo on parts and make people initialize it every time. I think this is non-sense. If there are a ways to make people write more correct code implicitly it will be better. – The_Ghost Oct 07 '13 at 10:12