Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell pattern matching not allowed in Elm?

Following this Elm tutorial and I assumed that the function

update : Msg -> Model -> Model

is defined in the tutorial as

update msg model = 
    case msg of
        Increment  -> model + 1
        Deccrement -> model - 1
        Reset      -> 0

I thought I would define it the same way but with syntax I prefer:

update Increment model = model + 1
update Decrement model = model - 1
update Reset model     = 0

But this doesn't compile, does Elm not support this syntax or did I make a mistake?

like image 236
Eben Kadile Avatar asked Dec 14 '22 22:12

Eben Kadile


1 Answers

One of the goals of Elm is to use a consistent style; removing redundant syntax is a conclusion of this. For that reason, you will not find any where clause and function definitions with multiple variants are not permitted either.

like image 85
Jan Tojnar Avatar answered Dec 20 '22 07:12

Jan Tojnar