Dear community,
a colleague of mine made me notice that in class definitions, the AST construct for self
is a pattern, as opposed to an (optional) variable. To be clearer, in the declaration:
class c = object (self) end
self
is considered as a pattern. And indeed, I can write, for example
class d = object (((_ as self) | self) as self2) end
which is legit OCaml code.
I fail to see, however, how other forms of patterns (tuples, variants, etc) can be used.
I am pretty sure I am missing something here.
Hence the question: why do we need such a general pattern construct for self
?
NB: I am not asking for any changes. I am just being curious.