> For the complete documentation index, see [llms.txt](https://orasund.gitbook.io/elm-cookbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://orasund.gitbook.io/elm-cookbook/recipes-1/making-impossible-states-impossible.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://orasund.gitbook.io/elm-cookbook/recipes-1/making-impossible-states-impossible.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
