Skip to content

Renaming function whose output is an E-class to constructor #422

@yihozhang

Description

@yihozhang

To emphasize the differences between functions whose output is an E-class ("constructor" function), which has unique semantics*, and other functions, we decided to change the syntax for declaring functions whose output is an E-class to use keyword constructor. So what used to be

(datatype E)
(function Add (E E) E)

should now be written as

(datatype E)
(constructor Add (E E) E)

Some non-constructors:

(datatype E)
(function best (E E) E :merge new) ;; because there is a merge expression
(function add1 (i64) i64) ;; because output is a primitive (and merge expression is an implicit `panic`)
(function upper-bound (E) i64 :merge (max old new)) ;; because it has a merge function

We should try to support this new constructor without breaking existing programs. So we should still support existing forms like (function Add (E E) E) but issue a warning to prompt the user.

*: constructor functions can be looked up in actions (cf. #420 for non-constructors) where it will be created on the fly (cf. #421 for non-constructors)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions