Closed izgzhen closed 5 years ago
or we might not want it because we want things to be sound -- both okay, just curious which might be better off
For whatever it's worth, here are my thoughts on various designs for partial functions like argmin
in Cozy. Note that the the
operator is another partial function that could also return null
instead of behaving how it does now, so it is also related to this topic.
{}
to {1}
because you added 1 to it, then the minimum goes from 0 to 1.argmin
. I like this design because it forces programmers to think more carefully about what should happen when you try to extract elements from an empty collection.min
computation directly, synthesis would need to introduce lots of extra primitives to "unpack" the optional value, which makes solutions have more AST nodes and therefore harder to discover.null
value. This would require a lot more run time checks from the code generator, and would introduce more overhead into the generated code. It also means that we cannot use, say, the native C++ bool
type because it does not have a null
value.min
return the set of all smallest elements in the collection rather than one of those smallest elements. This design is very elegant from an implementation standpoint: it does not introduce an optional type but represents the "optional" output using an empty or nonempty collection. Cozy already has many good heuristics for working with collections. However, I decided this design was too confusing from a specification-writer standpoint.
We should fix this to let argmin/max return null if the argument list is empty. this should simplify a lot of real world code, e.g. datastructure-synthesizer/followup/eval/mongo/spec.ds
Test: cozy argmin.ds