# Making impossible states Impossible

A good coding practice in Elm is to define the Model such that impossible states can not occur.

Instead of writing

```
type alias ServerRequest =
    { Response (Maybe String)
    , Failed (Maybe Error)
    }
    -- There can not be a Response and an Error at the same time.
```

one can use

```
type ServerRequest =
    Waiting
    Response String
    Failed Error
```

In this section we will look at common ways how to avoid impossible states.

## Further reading

* 🎥**Video:** [Making impossible states impossible](https://www.youtube.com/watch?v=IcgmSRJHu_8) by Richard Feldman
* ❗**Example:** [Tic Tac Toe](https://discourse.elm-lang.org/t/tictactoe-should-the-winner-be-part-of-the-model/3519/6)
* ❗**Example:** [Subset of {a,b}](https://www.reddit.com/r/elm/comments/bhpc7s/help_designing_my_model/)
* ❗**Example:** [Up to 2 choices of a set](https://www.reddit.com/r/elm/comments/b2yamr/modelling_problem_when_making_illegal_states/)


---

# 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://orasund.gitbook.io/elm-cookbook/recipes-1/making-impossible-states-impossible.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.
