Haskell laziness - how do I force the IO to happen sooner?

前端 未结 3 1097
暗喜
暗喜 2021-01-02 00:12

I just started learning Haskell. Below is some code written in an imperative style that implements a simple server -- it prints out the HTTP request headers. Besides the f

3条回答
  •  -上瘾入骨i
    2021-01-02 00:48

    You should probably have some notion of when a message is complete. You need to read from the input handle in snippets until you recognize that you've got a complete message. Then assume everything after that is the next message. Messages might not come all at once, or might come in groups.

    Messages might always be a fixed length, for example. Or terminated with \n\n (I believe this is the case for HTTP requests)

    [I may come back and post code to go with this advice, but if I don't, just try and adapt TomMD's code, which is a step in the right direction]

提交回复
热议问题