[m-dev.] Language interface improvements

Peter Schachte pets at students.cs.mu.oz.au
Wed Nov 19 11:24:20 AEDT 1997


On Wed, 19 Nov 1997, Fergus Henderson wrote:

> Zoltan Somogyi, you wrote:
> > Another tool we can possibly ask the student to write would be generating
> > the declarations and code for parsing and unparsing predicates for Mercury
> > types.
> 
> I think an approach based on type classes would be a better solution to
> this problem. 
> 
> We already have a design for this.  Types which need special
> printing should be members of the portrayable/1 type class; that is,
> they must have a portray/3 method.  print/3 does a dynamic type-class
> membership check to figure out whether the type being printed is a
> member of the type class portrayable/1.  If so, it calls the portray/3
> method.  Otherwise, it prints the data in the standard syntax

But don't forget the other half of what Zoltan asked about:  parsing.  You'd
need two type classes for input, say `readable' and `parsable' (maybe you
can think of better names), where readable:parsable::printable:portrayable.
Same idea:  read checks if the thing to be read is parsable, and if so calls
the parse code, otherwise it just invokes the usual read code.


-Peter Schachte			| Politicians are the same all over. They
pets at cs.mu.OZ.AU		| promise to build a bridge even where there is
http://www.cs.mu.oz.au/~pets/	| no river. -- Nikita Krushchev 
PGP key available on request	| 





More information about the developers mailing list