samer@0: % arr - Lift function to processing unit samer@0: % samer@0: % arr :: samer@27: % F:(A@typelist(N)->B@typelist(M)) ~'arbitrary function with N inputs and M outputs', samer@0: % options { samer@0: % nargin :: natural / nargin(F); samer@0: % nargout :: natural / nargout(F); samer@0: % } samer@27: % -> arrow(A@typelist(N),B@typelist(M),empty). samer@0: % samer@0: % The arr class is a class of arrows which simply apply an ordinary samer@0: % Matlab function to the inputs to obtain the outputs. In many cases, samer@0: % the number of inputs and outputs can be determined from the supplied samer@0: % function handle, but if the number arguments in or out is variable, samer@0: % then the nargin and nargout options must be used. samer@0: % samer@0: % The type empty denotes the type of empty arrays, ie samer@0: % the state of an arr arrow is always an empty matrix. samer@0: % samer@0: % arr(@log) - arrow which supplies the log of its input. samer@0: % arr(@plus) - sum two inputs to produce output samer@0: % arr(@(a,b)deal(a+b,a-b),'nargout',2) - computes sum and difference of inputs. samer@0: samer@0: function o=arr(fn,varargin) samer@0: if nargin==0, fn=@id; end samer@37: opts=options('nargin',[],'nargout',[],'sizefn',[],varargin{:}); samer@0: if isempty(opts.nargin), opts.nargin=nargin(fn); end samer@0: if isempty(opts.nargout), opts.nargout=nargout(fn); end samer@0: if opts.nargout<0, opts.nargout=1; end % assume 1 if we can't tell samer@0: o=class(struct('fn',fn,'sizefn',opts.sizefn),'arr',arrow(opts.nargin,opts.nargout)); samer@0: end