When using has_type/2 added more types via multifile which are working fine.
Then wanted to use
has_type(list(Type), X) :-
is_list(X), element_types(X, Type).
by calling has_type/2
from the module importing the library errors, and the code started failing.
As near as I can figure, element_types/2
(GitHub) needs to be exported.
Example
:- module(example, []).
:- use_module(library(error)).
% :- use_module(library(error),
% [
% element_types/2
% ]).
:- multifile
error:has_type/2.
error:has_type(key_value,Key_value) :-
key_value_validate(Key_value).
key_value_validate(Key_value) :-
must_be(ground,Key_value),
Key_value = kv(Key,Value),
must_be(ground,Key),
must_be(ground,Value).
:- begin_tests(example_bad).
test(1) :-
has_type(list(key_value),[kv(1,a),kv(2,b)]).
:- end_tests(example_bad).
has_type_workaround(list(Type), X) :-
is_list(X), error:element_types(X, Type).
:- begin_tests(example_workaround).
test(2) :-
has_type_workaround(list(key_value),[kv(1,a),kv(2,b)]).
:- end_tests(example_workaround).
?- run_tests.
% PL-Unit: example_bad
ERROR: d:/has_type_list_example.pl:28:
test 1: received error: plunit_example_bad:'unit body'/2: Unknown procedure: plunit_example_bad:has_type/2
done
% PL-Unit: example_workaround . done
% 1 test failed
% 1 tests passed
false.
Also tried using
:- use_module(library(error),
[
element_types/2
]).
instead of
:- use_module(library(error)).
which resulted in
?- consult('D:/has_type_list_example.pl').
Warning: d:/has_type_list_example.pl:9:
Warning: import/1: error:element_types/2 is not exported (still imported into example)
true.
Can use_module/2 be used to import predicates from modules that did not export the predicate? This has me confused.