The main issue of pattern matching

I noticed that [H|T] = [1].succeeds, but [H|T] = [].fails. I suppose how this works, but is there any reason why the designer did not decide that this template corresponded to a successful result and led to the appointment of H=[]and T=[]?

9> [H|T] = [1].
[1]
10> H.
1
11> T.
[]
12> [H|T] = [].
** exception error: no match of right hand side value []
+3
source share
2 answers

If [H|T]it matches []with H=T=[], then [[]]it will not differ from []using pattern matching.

[] [H|T] , , [H|T] , [] , .

[] " " .

+11

, @sepp2k , [] [_|_] , . .

0

Source: https://habr.com/ru/post/1793568/


All Articles