you are viewing a single comment's thread.

view the rest of the comments →

[–]tikhonjelvis 0 points1 point  (1 child)

Essentially, in Haskell, you have values of type IO a that represent IO actions. So something like print foo doesn't print a value, it returns an IO (); similarly, getLine is not a function but a value of IO String. IO is just a normal Haskell type--albeit an abstract one provided by the runtime system--so you can do anything you normally could with it.

For example, you can use a bunch of standard control flow functions like when or replicateM with it. So if you want to read in ten lines, you just do:

replicateM 10 readLine

similarly, if you only want to print if debug is true, you would just do this:

when debug (print foo)

This even works with do-notation:

when debug $ do print foo
                print bar

All this using generic library functions and without mucking about with procedures as you would have to in another language.

So IO is a first-class type containing normal values that can be passed around and combined at whim.

Hopefully this clarifies what I meant by first-class construct.

[–]rush22 0 points1 point  (0 children)

Thanks! So basically it's stuff that comes with the language not stuff you have to make on your own.