What's the exact number of types in Erlang? -


besides data primitives , structures found in other languages, what's full list of types in erlang?

for example, what's type of socket handle? , ets handle?

moreover, types impossible serialized , exchanged between nodes? think socket handle must 1 of them, right?

even among processes within same node, socket handle shared, right? that's exception of share-nothing principle?

what's behavior of gc against such shared stuff? , what's socket implementation in erlang? think it's not port, right?

there few types in erlang, , can refer functions is_???(term) of erlang module list of built in elementary types:

  • atom
  • bitstring
  • float
  • function
  • integer
  • list
  • map
  • pid
  • port
  • reference
  • tuple

there second list derived elementary types:

  • binary : bitstring size multiple of byte size
  • boolean : atoms true , false
  • number : integer or float
  • record : tuple first term atom representing record name (the compiler uses record definition access different elements of tuple symbol rather index)

then can consider can create infinite number of types based on combination of elementary types. in program see declaration such as:

-type orddict() :: [{key :: term(), value :: term()}]. 

or

-spec is_key(key, orddict) -> boolean() when       key :: term(),       orddict :: orddict(). 

those information not used directly erlang compiler, used external tools such dializer , not mandatory valid code. main feature in erlang not type declaration, pattern matching. thus, if call function , expect return value of form {ok,value} or {error,reason} write like:

result = case f(par) of     {ok,value} -> resultwhenok(value);     {error,reason} -> resultwhenerror(reason) end; 

or if don't care error management:

% name , age of employee id id in list of people list % using function return tuple of form % {peopletype, id, name,surname,age,sex} {ok,{employee,id,name,_,age,_}} = find_people(id,list); 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -