hydromatic / morel

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

Add an "inverter" concept, so that functions can generate lists of possible arguments #217

Open julianhyde opened 5 months ago

julianhyde commented 5 months ago

Consider the query

from s where String.isPrefix s "abcd";

We know how to invert the function and find the list of values of s such that String.isPrefix s "abcd" will return true. In fact it's a property of the String.isPrefix function.

So, we allow functions to declare inverters. In this case, the String.isPrefix function accepts the argument pattern "f a0 a1", and if argument 0 is the goal - the variable whose possible values we wish to enumerate - then we can generate the expression prefixesOf a1.

At first only built-in functions will be able to declare inverters. But later we will allow user-defined functions to define them. We may also convert existing logic - e.g. that a0 elem a1 can be inverted and a1 is the list of possible values of a0 - into inverters.

julianhyde commented 5 months ago

Work in progress: https://github.com/julianhyde/morel/tree/217-inverter