Add a Void type

Bug #489100 reported by Matt Giuca
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mars
Triaged
Wishlist
Matt Giuca

Bug Description

The fact that Mars lacks a Void type (a type with only a single value, meaning "no information") is annoying for two reasons: Firstly, functions which don't return anything need to be given an Int return type and always feature "return 0", and secondly, in the interactive mode, a 0 is always printed.

Note that you can write your own Void type (type Void: Void), but it wouldn't solve either problem because you would still need to write "return Void", and it would still print "Void".

I did not add a Void type for a long time because Mars is supposed to be a pure language, and it's not useful to have a pure function which returns no information. However, it has impure functions which perform IO (such as put_char), and those are fairly useful.

Add a new built-in type Void which has a single value, Void. Add two special rules. Functions with a Void return type do not require a return statement; they implicitly "return Void" at the end of the function body. In interactive mode, results of expressions of type Void are not printed. Note that Void is still a proper value; it can be passed as arguments or stored in variables (unlike in C), and an explicit "return Void" is also allowed. Also add a new rule that "return" without an expression implicitly returns Void (and only works in Void functions).

Note: If we implement subroutines, this would be useless (as all "Void" functions could just be subroutines without outputs). So consider implementing subroutines before going ahead with this.

Matt Giuca (mgiuca)
Changed in mars:
milestone: none → 0.4
Matt Giuca (mgiuca)
tags: added: language
Matt Giuca (mgiuca)
Changed in mars:
milestone: 1.0 → 1.1
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.