I’m learning Elm and I’m on this page of the guide. I tried typing
type alias Drink = { brand : String, color : String, liters : number }
but I got an Unbound Type Variable error:
The
Drink
type alias uses an unbound type variablenumber
in its definition:type alias Drink = { brand : String, color : String, liters : number } ^^^^^^
You probably need to change the declaration to something like this:
type alias Drink number = ...
Why? Well, imagine one
Drink
wherenumber
is an Int and another where it is
a Bool. When we explicitly list the type variables, the type checker can see
that they are actually different types.
Having just read this page of the guide, I don’t understand this error. Isn’t number
only constrained to Int
and Float
? And why does the number
type variable work in other contexts, like for the negate : number -> number
function?
Edit: While typing this up, I realized that the last paragraph of the error message was a general statement and not saying that number
can be a Bool
. It may be starting to click to me that when we create instances of type Drink
(is “instances of type Drink
” the right verbiage?), we need to know whether the liters
field is an Int
or Float
. But why would that need to be so explicit?