I'm currently trying to learn the idiomatic way to write F# code. The code simulates a basic calculator with only binary plus, minus and unary minus.
I'd like to know if there is a better way to group union cases than the way I did it. Should the
Add/Sub/MinusExpression be cases in the Expression union? Is there a better way to write the
type Expression = | BinExpression of BinExpression | UnExpression of UnExpression | IntExpression of int and BinExpression = | AddExpression of Expression * Expression | SubExpression of Expression * Expression and UnExpression = | MinusExpression of Expression let rec eval tree = let evalBin tree = match tree with | AddExpression(e1, e2) -> (eval e1) + (eval e2) | SubExpression(e1, e2) -> (eval e1) - (eval e2) let evalUn tree = match tree with | MinusExpression(v) -> -(eval v) match tree with | BinExpression(e) -> evalBin e | UnExpression(e) -> evalUn e | IntExpression(v) -> v