How can I write in Erlang an equivalent of this Haskell snippet?
name@(x:xs)
Pattern matching consists of specifying patterns to which some data should conform and then checking to see if it does and deconstructing the data according to those patterns. When defining functions, you can define separate function bodies for different patterns.
We use pattern matching in Haskell to simplify our codes by identifying specific types of expression. We can also use if-else as an alternative to pattern matching. Pattern matching can also be seen as a kind of dynamic polymorphism where, based on the parameter list, different methods can be executed.
You can do it with syntax like Name=[X|Xs]
. An example usage is
headlist([H|T]=L) -> io:format("List (~p) with head ~p ~n",[L,H]).
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