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