Hi Tim, I think the comma might be what's tripping up the pattern matching:
type Expression = Const Int | Mul Expression Expression calculate expr = case expr of Mul (Const 1) x -> x Mul x (Const 1) -> x _ -> expr On Sat, Mar 25, 2017 at 5:43 PM, Tim Elliot <[email protected]> wrote: > I have a beginner question about pattern matching. > > I'm trying to learn Elm from OCaml. playing around with math expressions. > > How would I pattern match against any Expression x in the example below? > > > type Expression > = Const Int > | Mul (Expression Expression) > > > calculate : Expression -> Expression > > calculate expr = > case expr of > Mul(Const 1 ,* x*) -> *x* > Mul(*x*, Const 1 ) -> *x* > _ -> expr > > > I get a bunch of these errors, : > -- TYPE MISMATCH ------------------------------ > --------------------------------- This tuple is causing problems in this > pattern match. 13| Mul(x, Const 1 ) -> x ^^^^^^^^^^^^^ The pattern > matches things of type: ( a, b ) But the values it will actually be > trying to match are: Expression Expression > > -- > You received this message because you are subscribed to the Google Groups > "Elm Discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
