我想知道erlang中struct和error的使用
例如,我很难理解这种语法
{error, bad_amount} -> {struct, [{"status", "error"}, {"reason", "badamount"}]};
最好的尊重巴蒂斯塔
我想知道erlang中struct和error的使用
例如,我很难理解这种语法
{error, bad_amount} -> {struct, [{"status", "error"}, {"reason", "badamount"}]};
最好的尊重巴蒂斯塔
The struct
and error
atoms does not really mean anything in Erlang. It is just atoms, tags that identifies what type of tuple you have. The first tuple is just two atoms. The second is a tuple with the first element being an atom (the tag) and the second being a list of tuples.
Tagging is an Erlang convention. It is a common thing to do (so common that records are implemented as tagged tuples). Tagging is the nearest a type system you get in Erlang since you make the values carry type information, and the tags are commonly used for pattern-matching.