public void checkInputs(List inputs) throws IllegalArgumentException {
        Object [] list = inputs.toArray();

        // first off, check that we got the right number of paramaters
        if (list.length != 3)
            throw new IllegalArgumentException("requires three inputs");

        // now, try to cast the first element into a function
        Function function = null;

        if (list[0] instanceof Function) {
            function = (Function)(list[0]);
        } else if (list[0] instanceof VariableReference) {
            Expression xpr = ((VariableReference)(list[0])).
                getReferencedDefinition().getExpression();
            if (xpr instanceof Function)
                function = (Function)xpr;
        }

        if (function == null)
            throw new IllegalArgumentException("first arg to higher-order " +
                                               " function must be a function");
        
        // check that the function returns a boolean
        if (! function.getReturnType().toString().
            equals(BooleanAttribute.identifier))
            throw new IllegalArgumentException("higher-order function must " +
                                               "use a boolean function");

        // get the two inputs
        Evaluatable eval1 = (Evaluatable)(list[1]);
        Evaluatable eval2 = (Evaluatable)(list[2]);

        // the first arg might be a bag
        if (secondIsBag && (! eval1.returnsBag()))
            throw new IllegalArgumentException("first arg has to be a bag");

        // the second arg must be a bag
        if (! eval2.returnsBag())
            throw new IllegalArgumentException("second arg has to be a bag");

        // finally, we need to make sure that the given type will work on
        // the given function
        List args = new ArrayList();
        args.add(eval1);
        args.add(eval2);
        function.checkInputsNoBag(args);
    }