% arr - Lift function to processing unit
%
% arr :: 
%    F:(A:arglist(N)->B:arglist(M)) ~'arbitrary function with N inputs and M outputs',
%    options { 
%       nargin  :: natural / nargin(F);
%       nargout :: natural / nargout(F);
%    }
% -> arrow(A:arglist(N),B:arglist(M),empty).
%
% The arr class is a class of arrows which simply apply an ordinary
% Matlab function to the inputs to obtain the outputs. In many cases,
% the number of inputs and outputs can be determined from the supplied
% function handle, but if the number arguments in or out is variable,
% then the nargin and nargout options must be used.
%
% The type empty denotes the type of empty arrays, ie
% the state of an arr arrow is always an empty matrix.
%
% arr(@log) - arrow which supplies the log of its input.
% arr(@plus) - sum two inputs to produce output
% arr(@(a,b)deal(a+b,a-b),'nargout',2) - computes sum and difference of inputs.

function o=arr(fn,varargin)
	if nargin==0, fn=@id; end
	opts=prefs('nargin',[],'nargout',[],'sizefn',[],varargin{:});
	if isempty(opts.nargin), opts.nargin=nargin(fn); end
	if isempty(opts.nargout), opts.nargout=nargout(fn); end
	if opts.nargout<0, opts.nargout=1; end % assume 1 if we can't tell
	o=class(struct('fn',fn,'sizefn',opts.sizefn),'arr',arrow(opts.nargin,opts.nargout));
end
