[Haskell-beginners] Question on Lazy IO

Chul-Woong Yang cwyang at aranetworks.com
Thu Jul 24 09:03:13 UTC 2014


Wow. DeepSeq is cool!
I 'deepseq'ed received request header and everything is OK.

Thanks Santtu!


2014-07-24 16:53 GMT+09:00 Santtu Keskinen <laquendi at gmail.com>:

> Hi Chul-Woong,
>
> Deepseq package can be used to make sure a list is actually fully
> constructed before it's used.
>
> import System.IO
> import Control.DeepSeq
>
> main :: IO ()
> main = do
>     s <- getContents
>     s `deepseq` hClose stdin
>     putStrLn "ECHO result"
>     putStr s
>
> Cheers
>
>
> 2014-07-24 9:07 GMT+03:00 양철웅 <cwyang at aranetworks.com>:
>
>> Hi, all.
>>
>> Haskell's lazy IO causes below program to
>> write back "ECHO result" to the user
>> even if he doesn't give any input to the program.
>>
>> test1 :: IO ()
>> test1 = do
>>   l <- fmap lines getContents
>>   putStrLn "ECHO result"
>>   putStr $ unlines l
>>
>> If the client logic, that is the part for feeding data to this program
>> and wait for the response, expect the server logic to respond
>> only after all the client's request data are feed to the server logic,
>> the behaviour could be problematic.
>>
>> I'm now writing simple web server, as you might guess, and
>> my web server responds "HTTP/1.1" before any client's request
>> are given. I'm using hGetContents and web server's logic is
>> basically same with above code skeleton.
>>
>> How can I tell the program to respond data only after all the
>> requests are feed? Any directions are welcomed.
>> Thanks.
>>
>> Chul-Woong
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140724/1d2b6a11/attachment.html>


More information about the Beginners mailing list