How can I poll files, sockets or handles to become readable/writable in Haskell?

The question is wrong: you aren’t forced to spawn one thread per file/socket and use blocking calls, you get to spawn one thread per file/socket and use blocking calls. This is the cleanest solution (in any language); the only reason to avoid it in other languages is that it’s a bit inefficient there. GHC’s threads are cheap enough, however, that it is not inefficient in Haskell. (Additionally, behind the scenes, GHC’s IO manager uses an epoll-alike to wake up threads as appropriate.)

Leave a Comment