Is there a better way of modeling data in F# to avoid needing it?
相关问题
- F#: Storing and mapping a list of functions
- Multiplying a list of tuples by a tuple in F#
- Multiplying a string in F#
- F# odd pattern matching issues
- Why doesn't bindingRedirect affect FSharp.Core
相关文章
- FSharp.Data.JsonProvider - Getting json from types
- Signing an F# Assembly (Strong name component)
- Learning F#: What books using other programming la
- fsc.exe is very slow because it tries to access cr
- Extension methods for specific generic types
- F# Object Initialization with a Constructor
- F# Lazy Evaluation vs Non-Lazy
- When to use interfaces, and when to use higher ord
The
protected
modifier 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 aprotected
member, the following code could be surprising:This code wouldn't work, because you're calling
Test
from 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 theprotected
modifier 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
protected
as 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 forprotected
in general (other than by avoiding implementation inheritance). Do you have some specific example which motivated your question?As to whether F# enables a better way of modeling data, signature files allow finer grained visibility decisions than
internal
does in C#, which is often very nice. See Brian's comment here for a little bit more explanation. This is independent of support (or lack thereof) forprotected
, though.