Is there a better way of modeling data in F# to avoid needing it?
Share
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
protectedmodifier can be quite problematic in F#, because you often need to call members from a lambda expression. However, when you do that, you no longer access the method from within the class. This also causes confusion when using protected members declared in C# (see for example this SO question). If you could declare aprotectedmember, the following code could be surprising:This code wouldn’t work, because you’re calling
Testfrom a lambda function (which is a different object than the current instance ofTest), so the code wouldn’t work. I think this is tha main reason for not supporting theprotectedmodifier in F#.In F# you typically use implementation inheritance (that is, inheriting from a base class) much less frequently than in C#, so you shouldn’t need
protectedas often. Instead, it is usually preferred to use interfaces (in the object-oriented F# code) and higher-order functions (in the functional code). However, it is difficult to say how to avoid the need forprotectedin general (other than by avoiding implementation inheritance). Do you have some specific example which motivated your question?