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
1
type alias ServerRequest =
2
{ Response (Maybe String)
3
, Failed (Maybe Error)
4
}
5
-- There can not be a Response and an Error at the same time.
Copied!
one can use
1
type ServerRequest =
2
Waiting
3
Response String
4
Failed Error
Copied!
In this section we will look at common ways how to avoid impossible states.

Further reading

Copy link