Replies: 3 comments 3 replies
-
Hi Alex, thanks for bringing this up and congratulations on being the first user to open a discussion : ) InheritanceIndeed, we could use some first-class support for this. Currently, inheritance among typeclasses is possible, but it requires a user-exposed encoding. See, for example: https://github.com/FStarLang/FStar/blob/master/examples/typeclasses/Num.fst#L24 Adding specialized syntax for this sounds like a good idea. You can expect something like that supported by F* soon. |
Beta Was this translation helpful? Give feedback.
-
Computed membersI'm not sure I quite see the need for this. Why couldn't one just write
? |
Beta Was this translation helpful? Give feedback.
-
As for adding inheritance and computed members to records: I think it's unlikely that we'll go in this direction. A record is just a single constructor inductive type. Typeclasses are the way to go for the kinds of structures you're talking about, with much success in other tools for describing algebraic structures, including, e.g., in Lean. |
Beta Was this translation helpful? Give feedback.
-
Just as the title says, I think records and typeclasses do need some love.
My motivation is, I am planning to introduce a flexible system for defining and using general algebraic structures in F*. And as we all know, relations between those are very difficult. There are lots of examples of multiple inheritance, for example.
As things currently are, if we were to start develop algebraic structures beyond the basic few, things will get ugly really quickly, and that is due to lack of language features
Here are some concrete suggestions:
Taste this, for example:
instance
declarations?Maybe what I'm suggesting goes against what you guys have in mind as the philosophy of F* -- then maybe we can have some other mechanism that would (a) give us fluent syntax for declaring such objects and (b) provide us with means for solving the diamond inheritance problem (that would offer us what is called virtual inheritance in C++), allowing for example to declare a commutative group that is both a group (magma ->semigroup->monoid->) and a commutative magma (magma ->), and just from the declaration it would be immediately clear that the resulting object is a magma and there are no two (possibly different) instances of
equality
, or definitions ofop
, or anything, -- and the object will be acceptable by any function that wants a magma, a commutative magma, a semigroup, a commutative semigroup, and so on.Beta Was this translation helpful? Give feedback.
All reactions