In the following code, the function disp is defined by de-constructing Sum b c and then immediately reconstructing it. The problem is that I don't need b and c, only the fact that it is of type Sum.
data Expr = Name String | Sum Expr Expr
deriving(Show)
disp (Sum (Name a) (Sum b c)) = a ++ ":" ++ disp (Sum b c)
Is there a way of writing disp without this deconstruction - reconstruction (and the b and c bindings), or is this the correct way of writing such a function?
disp (Sum (Name a) s@(Sum _ _)) = a ++ ":" ++ disp s
@ allows multiple matches for the same thing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With