[m-dev.] Allowing user-supplied term_to_univ_special_cases

Ondrej Bojar bojar at csse.unimelb.edu.au
Wed Feb 28 18:47:40 AEDT 2007


Hi,

would there be any objections in the Mercury office if I prepared a patch to 
allow users supply their own special-case handlers for converting term to univ 
and vice versa?

In other words, not only the default:

:- pred term_to_univ_special_case(string::in, string::in,
     list(type_desc)::in,
     term(T)::in(bound(functor(ground, ground, ground))),
     type_desc.type_desc::in, term_to_type_context::in,
     term_to_type_result(univ, T)::out) is semidet.

and the reverse

:- pred univ_to_term_special_case(string::in, string::in,
     list(type_desc)::in, univ::in, context::in, term(T)::out)
     is semidet.

e.g.:
...
univ_to_term_special_case("array", "array", [ElemType], Univ, Context, Term) :-
     Term = functor(atom("array"), [ArgsTerm], Context),
     has_type(Elem, ElemType),
     same_type(List, [Elem]),
     det_univ_to_type(Univ, Array),
     array.to_list(Array, List),
     type_to_term(List, ArgsTerm).
...

could be used, but the user could supply his own data-to-term serializer and 
term-to-data deserializer (bearing the same type/mode as 
term_to_univ_special_case/7 and univ_to_term_special_case/6).

Are there any technical problems why this would not be possible?

Do you prefer the user handlers (passed as higher-order arguments to 
univ_to_term and term_to_univ) to override the default behaviour or to extend 
the default behaviour of special handlers?

The motivation is clear: e.g. arrays are currently supported but not 
version_arrays. And my observation is that c_pointers are more and more used 
within user-defined data structures, so it is worth giving users the chance to 
implement serialization to term.

Thanks, Ondrej.

-- 
Ondrej Bojar (mailto:obo at cuni.cz / bojar at ufal.mff.cuni.cz)
http://www.cuni.cz/~obo
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the developers mailing list