Erlang Central  Hardcoding Expectations  Revision as of 07:31,
11 June 2007 by Rvg (Talk | contribs)   Rudolph van Graan   One
of the strangest things I had to get used when I started
programming in Erlang was to write correct programs (compared to
programs that handled all cases). This is one of the fundamental
rules in Erlang.  If you look at the code from Nested Cases, you
can see through inspection that the function can return one of
two possible values: null or {ok,Value}   1:
function(Operation,Values) ->  2:   case Operation of  3:
null ->   4:       null;  5:     multiply ->  6:
do_multiply(Values)  7:   end.  9: do_multiply([Value1,Value2])
when integer(Value1), 10:
integer(Value2)-> 11:   {ok,Value1*Value2}.  The return values
for all other input values are not defined. If you write code
that uses this function, you might be tempted to write something
like this:   1: main() ->  2:   Value1 = 10,  3:   Value2 = 20,
4:   case function(multiply,[Value1,Value