Reading this topic, I came to the question:
What is the purpose of the Kernel module?
As I understand it, it somewhat mirrors the :erlang
module and contains all functions available in guards. But the problem is, now some map functions are in both Map and Kernel, the same for List. So Kernel contains both functions that work on many datatypes and functions that work only on certain datatypes. If we add the new map_get/2
and is_map_key/2
, then map functions will be even more split between Kernel and Map.
This is what I see in Kernel:
- Functions/macros necessary for the structure of the language or that are useful to be default imported, operators/
def*
/if
/max
/is_*
etc. - Functions that operate on multiple data types,
get_in
/update_in
etc. - Functions that donât fit anywhere else, like maybe
apply
- Functions that work on single data types, like
hd
/length
/elem
/map_size
Now category #4 has always bothered me. Why are these functions not in modules, for example Tuple.elem/2
? It is very surprising for a new user to see that the most important functions operating on tuples for example are not in Tuple. Even from category #3 some functions could be moved to other modules, like now some spawn
functions are in Kernel and some are in Process.
If the reason is Kernel has all the functions that can be used in guards, I think that reasoning isnât so useful because I still have to go look at the list of functions that I can use in guards as Kernel has other functions as well. I donât remember the list offhand, so it wonât matter to me if itâs elem/2
or Tuple.elem/2
in the list.
Is there a technical reason for this mixed bag of stuff in Kernel? What does everyone else think about it? I donât mean to come off as abrasive about it and itâs not the end of the world, it doesnât come up that often when I program, but Iâm just wondering about the reasoning behind it.