[Haskell] Type problems

Donald Bruce Stewart dons at cse.unsw.edu.au
Sun Mar 11 18:37:44 EDT 2007

> 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

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:

Also, a lot of articles here:


-- Don

P.S. Best asked on the irc channel, you'll get a faster response :-)

More information about the Haskell mailing list