[Haskell] Type problems
Donald Bruce Stewart
dons at cse.unsw.edu.au
Sun Mar 11 18:37:44 EDT 2007
Dave:
> I am stumped trying to print values returned from IO functions.
> How to print values returned from getEnv and getEnvironment?
>
import System.Environment
main = do
args <- getArgs
env <- getEnvironment
print args
print env
You evaluate the IO action, extracting its result.
$ ./a.out hello
["hello"]
[("PATH","/home/dons/bin:/home/dons/bin:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/home/dons/bin:/sbin:/usr/sbin:/usr/local/sbin")....
Note that the do notation is just syntactic sugar for the >>= function,
getArgs >>= \ args ->
getEnvironment >>= \ env ->
print args >>
print env
It's probably a good idea to read up on monadic IO at some point. The best
references are:
http://darcs.haskell.org/yaht/yaht.pdf
http://en.wikibooks.org/wiki/Haskell
Also, a lot of articles here:
http://haskell.org/haskellwiki/Blog_articles
-- Don
P.S. Best asked on the irc channel, you'll get a faster response :-)
More information about the Haskell
mailing list