# Input / Output Actions

Haskell uses a special type `IO` to distinguish impure, input/output actions from pure expressions. The idea of the `IO` type is that apart from returning some value, it may also interact with the outside world along the way. The `IO` type has the following structure:

```haskell
IO a
```

where `IO` is the type name, and `a` is the parameterised value that it returns. For example:

```haskell
IO Int -- an action that returns an Int
IO () -- an action that returns an empty tuple, called a unit
```

The last example `IO ()` represents an action that is run solely for its side effects and simply returns an empty tuple (a void value or *unit*). Some **basic actions** in Haskell are:

```haskell
getChar :: IO Char       -- reads and returns a character from the screen
putChar :: Char -> IO () -- prints a character to the screen
return  :: a -> IO a     -- returns a value as an action
```

Note that, strictly speaking, `putChar` and `return` are not actions, but functions that return actions. The `return` function is simply our one-way bridge from the pure world to the impure world that we use when we want to use pure values in actions, which we will see in examples soon. For now, let's just try out the basic actions `getChar` and `putChar` in GHCi:

```haskell
ghci> getChar
1'1'            -- input is 1

ghci> getChar
'\n'


ghci> putChar 'a'
a

ghci> putChar '\n'

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://haskell.hpmeducation.com/interactive-programming/input-output-actions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
