anchor.diff:  
   -export([module/2,format_error/1]).
   
  --import(lists, [droplast/1,flatten/1,foldl/3,foldr/3,
  +-import(lists, [all/2,droplast/1,flatten/1,foldl/3,foldr/3,
                   map/2,mapfoldl/3,member/2,
   		keyfind/3,keyreplace/4,
                   last/1,partition/2,reverse/1,
  
positive.code:     end.
  
  map_remove_dup_keys(Es) ->
      dict:to_list(map_remove_dup_keys(Es, dict:new())).
  
  map_remove_dup_keys([{assoc,K0,V}|Es0],Used0) ->
      K = map_key_clean(K0),
      Op = case dict:find(K, Used0) of
  	     {ok,{exact,_,_}} -> exact;
  	     _                -> assoc
  	 end,
      Used1 = dict:store(K, {Op,K0,V}, Used0),
      map_remove_dup_keys(Es0, Used1);
  map_remove_dup_keys([{exact,K0,V}|Es0],Used0) ->
      K = map_key_clean(K0),
      Op = case dict:find(K, Used0) of
  	     {ok,{assoc,_,_}} -> assoc;
  	     _                -> exact
  	 end,
      Used1 = dict:store(K, {Op,K0,V}, Used0),
      map_remove_dup_keys(Es0, Used1);
  map_remove_dup_keys([], Used) -> Used.
  
  %% Clean a map key from annotations.
  map_key_clean(#k_var{name=V})    -> {var,V};
  
negative.code:     %%ok = io:format("match_value ~p ~p~n", [T, Css]),
      mapfoldl(fun ({Us,Cs}, St) -> match_clause(Us, Cs, Def, St) end, St1, UCss).
  
  %% partition_intersection(Type, Us, [Clause], State) -> {Us,Cs,State}.
  %%  Partitions a map into two maps with the most common keys to the
  %%  first map.
  %%
  %%      case <M> of
  %%          <#{a,b}>
  %%          <#{a,c}>
  %%          <#{a}>
  %%      end
  %%
  %%  becomes
  %%
  %%      case <M,M> of
  %%          <#{a}, #{b}>
  %%          <#{a}, #{c}>
  %%          <#{a}, #{ }>
  %%      end
  %%
  %%  The intention is to group as many keys together as possible and
  %%  thus reduce the number of lookups to that key.
  
  partition_intersection(k_map, [U|_]=Us, [_,_|_]=Cs0, St0) ->
      Ps = [clause_val(C) || C <- Cs0],
      case find_key_intersection(Ps) of
          none ->
              {Us,Cs0,St0};
          Ks ->
              Cs1 = map(fun(#iclause{pats=[Arg|Args]}=C) ->
                                {Arg1,Arg2} = partition_keys(Arg, Ks),
                                C#iclause{pats=[Arg1,Arg2|Args]}
                        end, Cs0),
              {[U|Us],Cs1,St0}
      end;
  partition_intersection(_, Us, Cs, St) ->
      {Us,Cs,St}.
  
  partition_keys(#k_map{es=Pairs}=Map, Ks) ->
      F = fun(#k_map_pair{key=Key}) ->
                  cerl_sets:is_element(map_key_clean(Key), Ks)
          end,
      {Ps1,Ps2} = partition(F, Pairs),
      {Map#k_map{es=Ps1},Map#k_map{es=Ps2}};
  partition_keys(#ialias{pat=Map}=Alias, Ks) ->
      %% Only alias one of them.
      {Map1,Map2} = partition_keys(Map, Ks),
      {Map1,Alias#ialias{pat=Map2}}.
  
  find_key_intersection(Ps) ->
      Sets = [cerl_sets:from_list(Ks) || Ks <- Ps],
      Intersection = cerl_sets:intersection(Sets),
      case cerl_sets:size(Intersection) of
          0 ->
              none;
          _ ->
              All = all(fun (Kset) -> Kset =:= Intersection end, Sets),
              case All of
                  true ->
                      %% All clauses test the same keys. Partitioning
                      %% the keys could only make the code worse.
                      none;
                  false ->
                      Intersection
              end
      end.
  
  