Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang's equivalent of Haskell's as-patterns

How can I write in Erlang an equivalent of this Haskell snippet?

name@(x:xs)

like image 552
ciembor Avatar asked Jan 17 '13 04:01

ciembor


People also ask

What is haskell pattern matching?

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.

Does Haskell have pattern matching?

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.


1 Answers

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]).
like image 200
Satvik Avatar answered Sep 21 '22 13:09

Satvik