erlang % Imperative Solution
Histogram = histogram(List),
-module(histogram).
-export([start/0]).
start() ->
List = [a, b, a, c, b, b],
% Imperative Solution
Histogram = histogram(List),
io:format("~w~n", [Histogram]).
histogram(List) ->
AccTbl = ets:new(the_map_name, [ordered_set, private, {keypos, 1}]),
ets:insert(AccTbl, lists:zip(List, lists:duplicate(length(List), 0))),
lists:foreach(fun (X) -> ets:update_counter(AccTbl, X, 1) end, List),
Histogram = ets:tab2list(AccTbl),
ets:delete(AccTbl),
Histogram.