%% $Id: mathserver.erl,v 1.2 2013/04/05 21:01:30 leavens Exp leavens $ -module(mathserver). -export([start/0]). -export_type([mathfunname/0]). -type mathfunname() :: sin | cos | tan | asin | acos | atan | sinh | cosh | tanh | asinh | acosh | atanh | exp | log | log10 | sqrt. -spec start() -> pid(). start() -> spawn(fun mserver/0). -spec mserver() -> none(). mserver() -> receive {Pid, compute, Funs, Arg} -> Pid!{ok,accumulate(lists:reverse(Funs),Arg)}, mserver() end. -spec accumulate([mathfunname()], float()) -> float(). accumulate([],Acc) -> Acc; accumulate([F|Fs],Acc) -> accumulate(Fs,math:F(Acc)).