2

What is the difference between IO (a) and IO a in Haskell?

For instance:

IO (String) vs IO String

IO (Int) vs IO Int

Most books I've seen wrap a type in parentheses before putting it after IO, but it's not obvious to me whether these are the same thing or not.

2
  • 2
    I'd recommend to follow the common style: never put parentheses around single identifiers as in (map) or (Int), in any expression or type context -- they are redundant and only add noise. Parentheses are still needed in (+) x y, f (g x), IO (Maybe Bool), for example. In (f x) + (g y) they are also redundant, but sometimes they can (arguably) add clarity. Still, there is no point in writing (x) -- you should avoid it. I'd hope books do not do that.
    – chi
    Commented Feb 23, 2022 at 11:09
  • @chi yes. The only exception is when writing parameterised C-preprocessor macros - and that is only because the C preprocessor essentially bypasses Haskell syntax completely. (And arguably, such macros should always be written in Template Haskell instead, however honestly CPP is a lot easier for simple ones, particularly easier to learn.) Commented Mar 11 at 15:06

1 Answer 1

8

There is no difference that would matter to the compiler.

Generally in Haskell, we like to avoid any unnecessary parentheses, so IO String is the preferred style. But of course you do need parens for e.g. IO (Maybe Int).

Not the answer you're looking for? Browse other questions tagged or ask your own question.