I have a 'sub state':
type SubState =
| DoingA
| DoingB
| AFewMore
and a main state:
type State =
| Initializing
| DoingStuff of SubState
| DoingNothing
and then I use that state in a match statement:
let state : State = ...
match anotherState with
| hello -> ()
| hello when state = Initializing -> ()
| hello when state = DoingStuff -> () <- won't compile
| hello when state = DoingStuff _-> () <- won't compile either
so I have to add to my State a helper:
type State =
| Initializing
| DoingStuff of SubState
| DoingNothing
member this.IsDoingStuff =
match this with
| DoingStuff _ -> true
| _ -> false
and then I can do my main match with:
match anotherState with
| hello -> ()
| hello when state = Initializing -> ()
| hello when state.IsDoingStuff -> () <- this works
but I would really like
| hello when state = DoingStuffAndIDontCareAboutTheSubState -> ()
Is there a nice syntactic way to the when condition and ignore the value of 'DoingStuff'?
I understand I could do:
match anotherState, state with
| hello, DoingStuff _ ->
but in many cases, I don't need the second value, so I'm trying to find a solution where I can keep the when statement.