[Haskell-cafe] IO inside CGI

Adrian Neumann aneumann at inf.fu-berlin.de
Fri Aug 24 10:12:36 EDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

I'm toying around with web programming in Haskell. I'm trying to write a
script which GETs an id and returns a couple of random numbers.
Something like this:

cgiMain :: CGI CGIResult
cgiMain = do
	inp <- getInput "id"
	let gen = parse inp
	output $ take 10 (randoms gen)

parse :: Maybe String-> StdGen
parse (Just x) = read x
parse Nothing = undefined

Now I'd like to get a new StdGen, in case no id was supplied to the script.

cgiMain :: CGI CGIResult
cgiMain = do
	inp <- getInput "id"
	gen <- parse inp
	output $ take 10 (randoms gen)

parse :: Maybe String-> IO StdGen
parse (Just x) = return $ read x
parse Nothing = getStdGen

Obviously this doesn't work because I'm trying to do IO inside CGI
(right?). Is there some incantation I can perform to make this possible?
Like

gen <- arcaneMagic parse inp

As you probably have noticed I don't know very much about monads, all I
did until now was reading or writing some files.

Thanks in advance
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGzudU11V8mqIQMRsRA33RAJ9buZDHgz/eXi8Jw9OBwbTErDccRgCfbGrr
1WXiGHmxlTBe01E409yJyv8=
=XSDj
-----END PGP SIGNATURE-----


More information about the Haskell-Cafe mailing list