Example:
?- must_be(chars, [a,X,cc]).
error(type_error(character,cc),can_be/2).
See https://github.com/mthom/scryer-prolog/pull/1474#issuecomment-
1126664368
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
I place this code in the public domain. Use it in any way you want.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
must_be_(atom, Term) :- check_(atom, atom, Term).
must_be_(character, T) :- check_(error:character, character, T).
must_be_(chars, Ls) :-
+ can_be(chars, Ls), % prioritize type errors over instantiation errors
must_be(list, Ls),
( '$is_partial_string'(Ls) ->
% The expected case (success) uses a very fast test.