I’m writing a predicate to encode some typing information, but I want this to be multifile and discontiguous. So I have, in typeDecls.pl:
:- module(typeDecls, [(::)/2]).
:- op(500, xfx, ::).
:- multifile((::)).
:- discontiguous((::)).
[] :: list(_).
[X|Xs] :: list(A) :- X :: A, Xs :: list(A).
%%% Some more stuff
Then I might have other files that define data structures, with the associated typing information; for example, in file tree.pl, I have:
:- module(tree, [showTree/1]).
:- use_module(library(clpfd)).
:- use_module(typeDecls).
%%% NOTE this clause of the typing predicate
node(Node, Subforest) :: tree(NodeType) :-
Node :: NodeType,
Subforest :: list(tree(NodeType)).
showTree(T) :- showTree(T, 1).
showTree(node(Node, SubForest), Depth) :-
once((
writeLevel(Depth), write(' '), print(Node), write('\n'),
DepthNext #= Depth+1,
maplist({DepthNext}/[T]>>showTree(T, DepthNext), SubForest)
)).
%%% Some more stuff
And wrapping this up, I might have in my main file something like:
:- use_module(typeDecls).
:- use_module(tree).
%%% Some more stuff
When I consult the main file, I’m getting the error:
ERROR: /home/.../tree.pl:5:22: Syntax error: Operator expected
and that position corresponds to my instance of the typing clause in tree.pl, as if that file couldn’t see the operator declaration in typeDecls.pl. Could you suggest how to fix this problem?
Thanks
Carlo