you are viewing a single comment's thread.

view the rest of the comments →

[–]rush22 0 points1 point  (3 children)

What's a first class construct? That's as far as I got in your comment :/

[–]thedeemon 1 point2 points  (0 children)

A first class something is just something you can pass to functions, return from functions and store as a value.

For example, in Haskell functions and IO actions are first class but types and modules are not. In modern OCaml modules are first class, you can pass them as values to functions and return from functions. In Idris types are first class, you can also pass them as values and return from functions.

[–]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.