title: map pattern matching in Erlang, unexpected error (unbound)
body: <p>The code below is basically copied from J.A.'s book:</p>
  
  <pre><code>-module(mapz).
  -export([count_chars/1]).
  
  count_chars(Str) -&gt;
      count_chars(Str, #{}).
  
  count_chars([H|T], #{H := N}=X) -&gt; % line that throws
      count_chars(T, X#{H := N+1});
  count_chars([H|T], X) -&gt;
      count_chars(T, X#{H =&gt; 1});
  count_chars([], X) -&gt; X.
  </code></pre>
  
  <p>however, compiling it in the shell gives me</p>
  
  <pre><code>151&gt; c(mapz).
  mapz.erl:7: variable 'H' is unbound
  error
  152&gt;
  </code></pre>
  
  <p>I understand the importance of having H bound before it can be used for matching a key in a map; and, as far as I can tell, it is being matched to the head of the list(string) in the first argument, and is therefore bound by the time the second argument (matching against the map) is evaluated. More to the point, the example being from the book, I suspect it to be correct. The book seems to be using OTP17, however, and I'm now on 20, wonder if things have changed? But which things?</p>
  
  <p>Thank you for your time.</p>