Scope in Reason

Nik Graf
InstructorNik Graf
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 5 years ago

Reason has lexical scope. In this lesson we explore what this means for the visibility of bindings using local block scopes.

Instructor: [00:00] Reason has lexical scoping. Don't worry in case you aren't familiar with this term, as in this lesson, I will guide you through the relevant implications.

[00:09] First, we create the local scope using curly braces. It can contain one or multiple imperative statements, while the last one will automatically be returned. In this case, the value of the scope is the same as if we would type 42.

[00:29] Inside a scope, we can access bindings outside of its current scope, but let bindings defined inside a scope aren't accessible from the outside. In fact, we can shadow a let binding inside a scope, and it won't affect the let bindings outside of this local scope, even with different types.

[00:53] Here, we bind the string Hello to the name foo. Then we create the scope where we bind the integer two to the name foo again. If you refer to foo outside of the block, it's still Hello. Since every block returns the last statement as an expression, we can also bind the result to a name.

[01:25] In the coming lessons, we will see blocks being used many times to create a local scope for constructs like switch expressions or function definitions. Keep in mind, every time curly braces are used in Reason, it's the same scoping behavior.

~ 25 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

Be on-Topic

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

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