You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It should be possible to provide default record field definitions in record type declarations. It should be possible to define default functions using the ordinary function definition syntax. This is especially useful when defining traits. For example, in the Ord trait we would really like to have separate fields for <, <= and == with default definitions, because e.g. for numbers they have more efficient implementations than matching on the result of Ord.cmp.
trait
type Ord A := mkOrd {
cmp : A -> A -> Ordering
(<) (x y : A) : Bool := case cmp x y of {
| LT := true
| _ := false
};
..
};
The text was updated successfully, but these errors were encountered:
We have discussed online some syntax options for record default values.
Braces around implicit arguments with default values.
Pros:
Consistent syntax where we have {} around every implicit argument. In fact, it is the same syntax that we use in function definitions on the left of the :.
Cons:
Can be a bit ugly/confusing with braces around multiline functions.
Probably does not feel natural at first. A good error message can help with this.
No braces around implicit arguments with default values.
Pros:
Arguably the most intuitive syntax. Intuitive in the sense that it is the syntax that a new user would most likely try before reading the documentation.
Pretty.
Cons:
Inconsistent with the syntax of implicit arguments without default value. I.e. If we have defined a field {A : T} for some record and we want to add a default value, we will need to remove the braces, which seems a bit odd.
Optional braces. This goes against uniformity and it can be too confusing.
It was suggested that we could rethink the syntax of implicit arguments and default values in a more general way with the goal of finding a syntax that feels more natural in all the parts of the juvix syntax. There were no concrete suggestions in this direction yet.
The team was split mostly between 1 and 2. We decided to go with 1 as a temporary implementation and adapt the syntax as needed in the future.
It should be possible to provide default record field definitions in record type declarations. It should be possible to define default functions using the ordinary function definition syntax. This is especially useful when defining traits. For example, in the
Ord
trait we would really like to have separate fields for<
,<=
and==
with default definitions, because e.g. for numbers they have more efficient implementations than matching on the result ofOrd.cmp
.The text was updated successfully, but these errors were encountered: