hydromatic / morel

Standard ML interpreter, with relational extensions, implemented in Java
Apache License 2.0
291 stars 15 forks source link

Allow `from` without `in`, and remove `suchthat` keyword #202

Closed julianhyde closed 5 months ago

julianhyde commented 9 months ago

In #129 we added suchthat for constrained relations, for example

from (i, j) suchthat i >= 0 andalso i < j andalso j < 4;

Reading Relational Expressions for Data Transformation and Computation (Pratten, Mathieson, 2023), I realized that if we just allow variables to be declared in from without an in clause - and therefore range over their entire data type - then that is sufficient. The suchthat keyword becomes unnecessary; any suchthat clause can become a where clause. The above example becomes

from i, j where i >= 0 andalso i < j andalso j < 4;

If you prefer, you can also alternate scans (introducing new variables) with filters:

from i where i >= 0,
   j where i < j andalso j < 4;