Skip to content

Default values for record fields #2427

@lukaszcz

Description

@lukaszcz

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
  };
  ..
};

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions