function u=construct(s,sizes_in)
	u=mkunit(s);
	nout=nargout(s);

	[fn,state]=s.init(sizes_in{:});
	u.sizes_out = guess_sizes(fn,nout,sizes_in,state);
	u.get_state = @get_state;
	u.set_state = @set_state;
	u.process   = ifx(nout>0,@proc,@proc0);

	function s=get_state, s=state; end
	function set_state(s), state=s; end
	function varargout=proc(varargin)
		[varargout{1:nout},state]=fn(varargin{:},state); 
	end
	function varargout=proc0(varargin)
		state=fn(varargin{:},state); 
	end
end

function sz_out=guess_sizes(fn,nout,sz_in,st)
	ins = map(@zeros,sz_in);
	if nout==0, s1=fn(ins{1},st); outs={};
	else [outs{1:nout},s1] = fn(ins{:},st); end
	sz_out = map(@size,outs);
end

