<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">On Thu, Jun 28, 2018 at 6:50 AM Dmitry Belyaev <<a href="mailto:be.dmitry@gmail.com">be.dmitry@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I could never understand where this conversion JSON null <-> Erlang undefined was coming from.</div><div><br></div><div>Of course we generally don't use null atom in the code, but I always considered "undefined" value in Erlang meaning "absent" value. For example when a record is created and some field is not populated explicitly, it is set undefined.</div></div></blockquote><div><br></div></div><div class="gmail_quote"><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">​Both variants are somewhat valid: Common Lisp generally treats NIL as the false value, the empty list, null, ... whereas other languages makes the distinction: [], false and null are different things in Erlang for instance.</div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default"><br></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">In a statically typed language, you probably would split them. In particular you would have</div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default"><br></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">type void</div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">type unit = ()</div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">type json = Int of int | String of string | ...  | Null</div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">​</div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">​Where 'void' is the uninhabitable type which can never be realized in a program​, 'unit' is the type of one result (and only that result) and a Null is something of type json.</div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default"><br></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">In Erlang, undefined often corresponds to the unit type. It isn't the same as void, because in Erlang every term has to return a value, and you cannot return something of type void.</div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default"><br></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">The tradeoff in the end is that of convenience: null == undefined means you can share some data, but you then lost the ability to discriminate null and undefined which from a type/class perspective might be desirable.</div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default"><br></div><br clear="all"></div><br>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">J.</div></div>