F# pattern matching when mixing DU's and other values
Posted
by Roger Alsing
on Stack Overflow
See other posts from Stack Overflow
or by Roger Alsing
Published on 2010-04-23T07:57:59Z
Indexed on
2010/04/23
14:53 UTC
Read the original article
Hit count: 274
F#
|pattern-matching
What would be the most effective way to express the following code?
match cond.EvalBool() with
| true ->
match body.Eval() with
| :? ControlFlowModifier as e ->
match e with
| Break(scope) -> e :> obj //Break is a DU element of ControlFlowModifier
| _ -> next() //other members of CFM should call next()
| _ -> next() //all other values should call next()
| false -> null
cond.EvalBool returns a boolean result where false should return null and true should either run the entire block again (its wrapped in a func called next) or if the special value of break is found, then the loop should exit and return the break value.
Is there any way to compress that block of code to something smaller?
© Stack Overflow or respective owner