shiika icon indicating copy to clipboard operation
shiika copied to clipboard

None as class

Open yhara opened this issue 2 years ago • 0 comments

Shiika has special treatment for enum cases with no arguments such as Maybe::None. While Some evaluates to #<class Maybe::Some>, None evaluates to #<None>, which is the only instance of the class Maybe::None.

So you don't need to write .new everytime you need None.

a = Some<Int>.new(1)
b = None

However there are some cases where we want to denote the class None.

  1. a = Result<None>.new
  2. match x; when None

It is easy to add special handling for such cases to the compiler, but how to explain the rule?

yhara avatar Jun 01 '22 13:06 yhara