What does the “object(self: something)” means in Ocaml, inheritance?
class tcp_messaging my_address my_cookie (drop_it: drop_function) =
....
object(self : # messaging )
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The sharp sign in front of a class name denotes a class type which contains at least the type of the class, so it is more or less an interface denotation.
Ocaml doesn’t have a special keyword to reference an object in its implementation (like the keyword
thisin C++ for instance). Instead, it provides a flexible syntax to define the name which will be used to reference the object instance (in this case the nameselfis used). It appears that this naming is actually the one used generally (it’s kind of a practice), so you will see it very often.So basically, that syntax let you bind the object to a name, and add a constraint on that name, so that the implementation must implement at least that type. Without the
#, the class implementation would need to be exactly of that type.