Signature of IO in Haskell (is this class or data?)
haskell
Solution
You asked whether `IO a` is a data type: it is. And you asked whether the `a` is its type parameter: it is. You said you couldn't find its definition. Let me show you how to find it:
localhost:~ gareth.rowlands$ ghci
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Prelude> :i IO
newtype IO a
= GHC.Types.IO (GHC.Prim.State# GHC.Prim.RealWorld
-> (# GHC.Prim.State# GHC.Prim.RealWorld, a #))
-- Defined in `GHC.Types'
instance Monad IO -- Defined in `GHC.Base'
instance Functor IO -- Defined in `GHC.Base'
Prelude>
In ghci, `:i` or `:info` tells you about a type. It shows the type declaration and where it's defined. You can see that `IO` is a `Monad` and a `Functor` too.
This technique is more useful on normal Haskell types - as others have noted, `IO` is magic in Haskell. In a typical Haskell type, the type signature is very revealing but the important thing to know about `IO` is not its type declaration, rather that `IO` actions actually perform `IO`. They do this in a pretty conventional way, typically by calling the underlying C or OS routine. For example, Haskell's `putChar` action might call C's `putchar` function.
Problem
The question is not what `IO` does, but how is it defined, its signature. Specifically, is this data or class, is "`a`" its type parameter then? I didn't find it anywhere. Also, I don't understand the syntactic meaning of this: ``` f :: IO a ```