[m-dev.] io__write and arrays

Peter Schachte pets at cs.mu.oz.au
Tue Apr 8 15:15:25 AEST 1997


> `display' and `write' for user-defined Mercury types should be handled
> automatically, using arg & functor and the predicates exported from
> library/ops.m.  For user-defined types that are actually defined using
> C code, then in the long term we should probably also do this with type
> classes, but in the short term, we should at least handle the types
> defined in the standard Mercury library, in particular arrays.

This is actually a little bit tricky (even with type classes).  If you're
always meant to be able to read back in the output of display, how do you
display a C-implemented type?  On a related topic, how should users write
manifest constants of a C-implemented type?

I suppose for now we can say you can't, but in the long run these are both
very desirable.  One possible solution would be to have a general
metasyntax for C-implemented types.  For the purposes of discussion let's
use the syntax #Typename{...}, where "Typename" could be any type name,
and the interpretation of the "..." depends on the type.  For example, an
integer array of 1, 2, and 3 might be written #array{1,2,3}.  This is
ugly, but it'll do for discussion. 

For now, read could have special cases for the Typenames in the standard
library.  When we have type classes, then the named type would be expected
to be in the type class of readable special terms, and read (or maybe it's
the tokenizer?) would call the named type's parse_manifest_constant
predicate. 

One tricky part of this is that the "..." part will in general want to
contain terms, so read would have to be reentrant.  The other tricky bit
is getting from the type *name* to that type's parse_manifest_constant
predicate.

This is a very sketchy proposal, with all the detail left to be worked
out.  My main point for this message is that there is potentially a lot to
be gained from thinking about these issues now and deciding on a single
metasyntax for displaying and writing all C-defined types.


-Peter Schachte      URL:  http://www.cs.mu.oz.au/~pets/
pets at cs.mu.OZ.AU     PGP:  finger pets at 128.250.37.150 for key
    [A computer is] like an Old Testament god, with a lot of rules
    and no mercy.  -- Joseph Campbell




More information about the developers mailing list