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

Pages: 1-4041-

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-03-23 7:36 ID:HygyPdWL

what level is it? I bet mine is higher

Name: Anonymous 2007-03-23 7:41 ID:5xTxkJbS

>>2
>>1 is clearly not at satori level yet.  I suggest he meditates on it for a few decades and realizes that do-notation is considered harmful.

interactTCP port f = do
        servSock <- listenOn $ PortNumber (fromIntegral port)
        waitLoop f servSock


becomes (might have to replace the $ depending on operator precedence)

interactTCP port f = listenOn $ PortNumber (fromIntegral port) >>= waitLoop f

If you are Godlike, you'll be able to figure out a way of making the function pointless as well.

Name: Anonymous 2007-03-23 9:09 ID:iiESCrXA

>>3
Well you can cancel the 'f' arg for a start. It'll take a bit of manipulation to get rid of the 'port' arg.

Name: Anonymous 2007-03-23 10:36 ID:EoOzoEui

>>3
oh god please not syntactic sugar!
HASKELL SAYS syntactic sugar CONSIDERED HARMFUL

Name: Anonymous 2007-03-23 10:46 ID:5xTxkJbS

>>5
True that!

Name: Anonymous 2007-03-23 16:07 ID:1hUiyLgJ

There's some Haskell fag that has been spamming the board with Haskell since about a month ago. Must've just learn Haskell and be really eager to use it for everything.

Name: Anonymous 2007-03-23 16:09 ID:iiESCrXA

>>7
There's at least two of us actually (I'm a Haskell fag and I know that nearly all of the Haskell posts aren't mine).

Name: Anonymous 2007-03-23 16:19 ID:bViBizKl

>>8
(1+)

Name: Anonymous 2007-03-23 16:23 ID:AdcrJNSf

>>8
Same here!  I did start one Haskell thread this week though, and I troll a bit in most of them.  In fact, I already posted twice (not including this reply) in this thread ;)

Name: Anonymous 2007-03-23 16:30 ID:4n7w3DgL

>>8
Ohh, three! No, four! Holy flippin' fudge, we're like a total clique here!

Name: Anonymous 2007-03-23 16:50 ID:PKRnfEoG

Five. OP here. We should start our own firm or something: writin' (more like divinin') Haskell code during the day, prowling the parks for buttsex during the night!

Name: Anonymous 2007-03-23 17:10 ID:iiESCrXA

writin' (more like divinin') Haskell code during the night, prowling the elementary schools for buttsex during the night!

fix'd

Name: Anonymous 2007-03-23 17:32 ID:SbkrxVz7

Six. I don't usually post in the threads though.

Name: Anonymous 2007-03-23 17:48 ID:EoOzoEui

I know haskell but I think its stupid so I just belittle you haskell fags

Name: Anonymous 2007-03-23 17:59 ID:SbkrxVz7

>>15
How's that working out for you?

Name: Anonymous 2007-03-23 18:17 ID:iiESCrXA

>>13
Dammit I just reread my post and realised I forgot to change night to day :(

Name: Anonymous 2007-03-23 21:32 ID:4n7w3DgL

>>14
You _lurk_ on /prog/? Holy shit. How's purgatory treating you?

Name: Anonymous 2007-03-23 21:33 ID:4n7w3DgL

Oh hey, >>1's program isn't actually multithreaded. MEGA FAIL.

Name: Anonymous 2007-03-24 3:49 ID:gKwbvHtt

>>19
IT'S NOT??

Name: Anonymous 2007-04-11 19:52 ID:qlYG8jby

SEVEN

Name: Anonymous 2007-04-11 19:54 ID:MhPU501A

ONE

Name: Anonymous 2007-04-12 5:17 ID:G0xj58oE

SEVEN-SAN

Name: Anonymous 2007-04-12 10:47 ID:GIsIR5/c


$ ghc --make factorial.hs
Linking factorial ...
$ ./factorial
Broken pipe


um ok.. well done sir

Name: Anonymous 2007-04-12 13:59 ID:0onV9BeI

run it in ghci you nigger

Name: Anonymous 2007-04-12 14:09 ID:GIsIR5/c

hm no luck, am I supposed to supply some command line arguments to it or somthing?

$ ghci factorial.hs
Bus error

Name: Anonymous 2007-04-12 14:36 ID:0onV9BeI

>>26
You must be running some sort of nigger OS

$ ghci factorial.hs
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( factorial.hs, interpreted )
Ok, modules loaded: Main.
*Main> main
Loading package parsec-2.0 ... linking ... done.
Loading package html-1.0 ... linking ... done.
Loading package network-2.0 ... linking ... done.


$ nc 127.0.0.1 1234
5
120
10
3628800
50
30414093201713378043612608166064768844377641568960512000000000000
100
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

Name: Anonymous 2007-04-12 14:49 ID:goz+xSbJ

Works fine for me.

$ uname -mrsv
Darwin 8.9.0 Darwin Kernel Version 8.9.0: Thu Feb 22 20:54:07 PST 2007; root:xnu-792.17.14~1/RELEASE_PPC Power Macintosh

Name: Anonymous 2007-04-12 14:49 ID:inLg/6gb

Yes!  I have attained the knowledge of double argument pointless functions through countless hours of meditation!
> map . (,) :: a -> [b] -> [(a, b)]
FAP FAP FAP

Name: Anonymous 2007-04-12 14:53 ID:Heaven

>>29
You should publish a research paper. The world deserves to know.

Name: Anonymous 2007-04-12 15:03 ID:GIsIR5/c

>>29
I think you mean:
(map cons list)

Name: Anonymous 2007-04-12 15:09 ID:inLg/6gb

>>30
Sure -- but what should I call it?  I'm not good at coming up with brilliant titles such as "Distance preserving mappings from ternary vectors to permutations."

Name: Anonymous 2007-04-12 15:13 ID:GIsIR5/c

>>32
protip: no one gives a fuck tthat you can map the , operator across a list.

Name: Anonymous 2007-04-12 15:23 ID:goz+xSbJ

>>33
ssnake

Name: Anonymous 2007-04-12 15:26 ID:inLg/6gb

>>33
It doesn't just do that -- this is the equivalent pointful version:
> map ((,) a) b
As you can clearly see, it takes a single element, and a list of elements, and returns a list of pairs of the first argument with every element in `b'.

Name: Anonymous 2007-04-12 15:51 ID:Heaven

>>35
fuck off

Name: Anonymous 2007-04-12 16:00 ID:inLg/6gb

>>36
I'm glad I could be of help :)

(I assume ``fuck off'' is nigger-speak for ``thank you.'')

Name: Anonymous 2007-04-12 16:01 ID:GIsIR5/c

>>37
proof that haskell programmers are ractists.

Name: Anonymous 2007-04-12 16:13 ID:0onV9BeI

>>38
nigger

Name: Anonymous 2007-04-12 16:44 ID:DIXaUi3T

>>32
Use arrows.

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

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