polymorphism, part II

Tomas By T.By at dcs.shef.ac.uk
Sat Sep 27 20:23:52 AEST 1997


Hi all,

I have now experimented a bit and decided to Keep It Simple. Using
insts as subtypes was a complete mess -- the declarations were twice
as complicated and the error messages less helpful.

And I don't think forward/backward arguments are acceptable in a
library interface, so I'm using one procedure per mode instead.

The module inteface is included below. Constructive criticism
would be appreciated.

/Tomas

---------------------------------------------------------------
:- module xml.

:- interface.
:- import_module io.

:- type stream(T) == list(stream_item(T)).

:- type tree(T) == list(tree_item(T)).

:- type stream_item(T) ---> text(T)
                          ; start_tag(string,list(attribute))
                          ; end_tag(string)
                          ; spec(spec)
                          .

:- type tree_item(T) ---> text(T)
                        ; element(string,list(attribute),tree(T))
                        ; spec(spec)
                        .

:- type byte == char.

:- type word == string.

:- type attribute ---> string - string.

:- type spec ---> ref(ref)
                ; empty_tag(string,list(attribute))
                ; comment(string)
                ; procinstr(string,string)
                ; cdata(string)
                ; doctype(string)
                .

:- type ref ---> amp
               ; lt
               ; gt
               ; apos
               ; quot
               ; char(int,int) % Base, Number
               ; def(string)
               .

:- type error.

:- pred version(string).
:- mode version(out) is det.

:- pred read(stream(byte),list(xml__error),io__state,io__state).
:- mode read(out,out,di,uo) is det.

:- pred write(stream(byte),io__state,io__state).
:- mode write(in,di,uo) is det.

:- pred from_string(string,list(xml__error),stream(byte)).
:- mode from_string(in,out,out) is det.

:- pred to_string(stream(byte),string).
:- mode to_string(in,out) is det.

:- pred stream_to_tree(stream(T),list(xml__error),tree(T)).
:- mode stream_to_tree(in,out,out) is det.

:- pred tree_to_stream(tree(T),stream(T)).
:- mode tree_to_stream(in,out) is det.

:- pred byte_to_word(stream(byte),stream(word)).
:- mode byte_to_word(in,out) is det.

:- pred word_to_byte(stream(word),stream(byte)).
:- mode word_to_byte(in,out) is det.

:- pred valid(tree(_)).
:- mode valid(in) is semidet.

:- pred dump_stream(stream(T),pred(T,io__state,io__state),
                    io__state,io__state).
:- mode dump_stream(in,pred(in,di,uo) is det,di,uo) is det.

:- pred dump_tree(tree(T),pred(T,io__state,io__state),io__state,io__state).
:- mode dump_tree(in,pred(in,di,uo) is det,di,uo) is det.

:- pred dump_byte(byte,io__state,io__state).
:- mode dump_byte(in,di,uo) is det.

:- pred dump_word(word,io__state,io__state).
:- mode dump_word(in,di,uo) is det.

:- pred error_string(xml__error,string).
:- mode error_string(in,out) is det.
---------------------------------------------------------------




More information about the users mailing list