Let say I have some types
type A = { ... }
type B = { ... }
type AB = A of A | B of B
type Ainfo = { //some additional information about A
...
}
type Binfo = { //some additional information about B
...
}
type ABinfo = Ainfo of Ainfo | Binfo of Binfo
and there is a function which works with these types - it accepts 'entity' which can be A or B plus some additional information about this entity.
let myFunc (entity: AB) (info: ABinfo) = ...
How can I enforce complier restrictions to avoid cases when 'myFunc' is called with entity A and info Binfo and vice versa?
PS this question relates to my other question Extend type in F#
Atogether withBinfo? I know you're going to say "it shouldn't compile", but then my next question is: what if you don't even know what you're passing at the time of writing the program? Suppose, for example, that the two parameters of the function ultimately come from the user input. In this case, you cannot know what they will be until the user inputs them. So what should happen if the user inputs a wrong combination? - Fyodor Soikin