Skip to content

Instantly share code, notes, and snippets.

@dteoh

dteoh/unused-this.md

Last active Jun 2, 2020
Embed
What would you like to do?
Solving "unused variable this." warnings when using ReasonML objects

unused variable this

You can create objects in ReasonML. For example:

let document = {
  pub title = "My Treatise";
  pub contents = "<a lot of words>"
};

If you compile this, you will most likely get warning number 27 with message unused variable this..

You can solve this by adding as _; as follows:

let document = {
  as _;
  pub title = "My Treatise";
  pub contents = "<a lot of words>"
};
@ValeTheVioletMote

This comment has been minimized.

Copy link

@ValeTheVioletMote ValeTheVioletMote commented Jun 2, 2020

Why is this the case?

@dteoh

This comment has been minimized.

Copy link
Owner Author

@dteoh dteoh commented Jun 2, 2020

Why is this the case?

As in why is there a variable this? It is an object, and you can write functions in the object like:

pub someFunction = () => 42;
pub getAnswer = () => this#someFunction()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.