Consider the assoc library.
One aspect of it is that it has an “initializer” for an empty assoc: empty_assoc (?Assoc)
What if i were to wrap this predicate to add an attribute variable indicating the intended type of the assoc – say, its of type ‘a->b’
new_teacher_student_mapping(Assoc) :-
empty_assoc(Assoc)
add_type('teacher->student', Assoc). % adds the type symbol as attribute variable to Assoc
get_students(Assoc, Students) :-
must_be_of_type('teacher->student', Assoc), % raise exception, if wrong type
assoc_to_values(Assoc, Students).
Btw, this can be done without attribute variables. For example, by returning a pair instead of a vanilla assoc, and then checking for that pair.
How do these two approaches compare – e.g. performance wise.
All predicates that subsequently expect an assoc as argument could have a type check, by retrieving the assoc and checking for the expected type.
Is this something that could be done with attribute variables?
thanks,
Dan