You have to note that Erlang differentiates atoms and identifiers using their case.
Eg:
[a, b, bla, key_1, val_X]
is a list of atoms[A, B, Bla, Key_1, Val_X]
is a list of variables
In your code you defined F
so that it behaves a certain way for specific atoms as input.
What you should have done (and what they did in your link) is use variable identifiers:
F = fun({Key_X, Val_X},{Key_Y, Val_Y}) -> {Val_X, Key_X} =< {Val_Y, Key_Y} end.
See?