A formal basis for horn clause logic with external polymorphic functions