Helping The Compiler Help Us With Variants
ReasonML gives us something called a variant which is similar to what other language call enums and union types. By defining a variant, we give the compiler some information about exactly what values a variable can take on -- its allowed variants.
Here we define the kinds of roles that users in our system can have as well as a user
type for representing individual users:
And here is how we might use it in some authorization code:
We've neglected to include Admin
in our switch statement. The compiler will inform us of this with a warning.
this pattern-matching is not exhaustive. Here is an example of a value that is not matched: Admin
Last updated