Using Reason's Type option

Nik Graf
InstructorNik Graf
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 5 years ago

ReasonML doesn't null. Still sometimes we want to refer to something and don't know ahead if a corresponding value will be available. Reason therefor offers the Variant option shipping with the standard library.

Instructor: [00:00] Before we explore the type option, you need to understand why it's needed. For example, if you try to bind null to the integer H, it doesn't work. Null simply does not exist.

[00:12] This is great, since null is the cause for many, many bugs. In fact, its inventor, Sir Tony Hoare, stated, "I call it my billion-dollar mistake, was the invention of the null reference in 1965."

[00:28] Nevertheless, null serves a purpose. Sometimes you want to refer to something, and don't know ahead if the corresponding value will be available. Reason therefore offers the variant option, shipping with the standard library.

[00:43] An option has two constructors, for one's none, indicating that no value is available, and then some, indicating that there is a value. It is passed in as an argument of any type. We combine any of those to name. As with any other variant, we can use it in combination with the switch expression.

[01:24] This is really great. With option, we have a tool at our disposal that allows us to simulate a novel value while still being type safe, meaning a pure Reason program doesn't have null errors. What a blaze.

egghead
egghead
~ 10 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today