millet icon indicating copy to clipboard operation
millet copied to clipboard

Support `lazy` keyword

Open RobertHarper opened this issue 2 years ago • 5 comments

Problem

SML/NJ supports laziness via the Control.lazysml boolean reference, which if set to true enables "lazy" as a keyword on datatype declarations and on val [rec] declarations.

eg, datatype lazy stream = Cons of int * stream eg, val rec lazy zeros = Cons (0, zeros)

Solution

It would be great to have a way to enable highlighting of the keyword "lazy" as with the other constructs of the language.

RobertHarper avatar Mar 20 '23 14:03 RobertHarper

Shouldn't be too hard to parse/syntax highlight this keyword. I'm interested, though, how it affects the static semantics. Is there a formalization written up that i may consult to know how it affects typechecking?

azdavis avatar Mar 20 '23 23:03 azdavis

There's also some compatibility considerations - if this 'laziness' feature is not enabled, then val lazy = 3 should not syntax error. In other words, lazy should only sometimes be a keyword.

azdavis avatar Mar 21 '23 05:03 azdavis

Yes, it should be an optional feature, the question is how to indicate that it's "on"? In SML/NJ it's a matter of an assignment to a variable.

As to the statics the paper by MacQueen and Taha (and possibly another) does it: https://www.diva-portal.org/smash/get/diva2:413532/FULLTEXT01.pdf.

RobertHarper avatar Mar 21 '23 16:03 RobertHarper

re: indicating it’s on: i was thinking a config option in millet.toml.

as for implementing this feature, it looks like you can translate down the “lazy” language into the regular language with some local transformations.

the only probably i foresee in millet is that millet does not currently have the ability to transform the code as it is typechecking.

i think we’d need the ability to do that, or at least, we’d need to have scoping/name resolution information, because we need to track which data types and vals are lazy in order to transform their usage sites. but name resolution requires the rest of typechecking in sml because of the module system.

azdavis avatar Mar 24 '23 02:03 azdavis