Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Haskell mutithreaded factorial server

Name: Anonymous 2007-03-23 6:35 ID:PKRnfEoG

Taking the Haskell factorial joke to a new level

module Main where

import Control.Concurrent
import Control.Exception
import System.IO
import Network

interactTCP :: Int -> (String -> IO String) -> IO ()
interactTCP port f = do
        servSock <- listenOn $ PortNumber (fromIntegral port)
        waitLoop f servSock

waitLoop :: (String -> IO String) -> Socket -> IO t
waitLoop f servSock = do
        (h,_,_) <- accept servSock
        forkIO $ finally (y (\f' ->
            (do hSetBuffering h LineBuffering
                hGetLine h >>= f >>= hPutStrLn h >> f')))
                         (hClose h)
        waitLoop f servSock

factorial :: Integer -> Integer
factorial = product . enumFromTo 1

readApplyShow :: (Read a, Show c) => (a -> c) -> String -> String
readApplyShow f = show . f . read

y :: (t -> t) -> t
y f = f (y f)

main :: IO ()
main = interactTCP 1234
                   (return . readApplyShow factorial)

Name: Anonymous 2007-04-12 16:53 ID:teoF8F5n

lol. virgins.

Name: Anonymous 2007-04-12 18:25 ID:p5KPWWOO

>>39
racist

Name: Anonymous 2007-04-12 18:29 ID:B3ZQZNF7

>>42
Ractist!

Name: Anonymous 2007-04-13 3:13 ID:Qxf4wakS

>>40
Hmm... perhaps, but I still need a title for my paper :/

Name: Anonymous 2007-04-13 3:31 ID:kVk9ocAP

>>44
How about ``A generalized method for tacit one-to-many pairwise Cartesian product computation''?

Name: Anonymous 2007-04-13 8:10 ID:wP+XnXoF

>>45
iCame!

Name: Anonymous 2009-01-14 14:10

BBCODE Failure

Name: Anonymous 2010-12-27 5:46

Name: Sgt.Kabu⼆ʕkiman뷽뤲 2012-05-28 23:41

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List