[m-users.] Problem with XML extra library
Volker Wysk
post at volker-wysk.de
Thu Jun 23 17:11:55 AEST 2022
Hi
I'm trying to acquaint myself with the XML library in "extras".
There's "tryit.m", which is a simple example of using the library, which
compiles fine. It is like this:
-----
...
:- pred main(io::di, io::uo) is det.
:- implementation.
...
main -->
io.command_line_arguments(Args),
main(Args).
:- pred main(list(string), io, io).
:- mode main(in, di, uo) is det.
main([]) --> [].
main([File|Files]) -->
...
{ TextResult = ok(Text) },
pstate(mkEntity(Text), mkEncoding(utf8), init),
...
-----
The two "main" predicates are written in DCG syntax. The call to pstate/5 is
therefore (??) an abbreviation of
pstate(mkEntity(Text), mkEncoding(utf8), init, !IO)
But the declaration of pstate/5 in parsing.m is:
:- pred pstate(entity, encoding, globals, io, pstate(unit)).
:- mode pstate(in, in, in, di, puo) is det.
So the type of the output state variable is "pstate(unit)". But it is "io",
when main/3 is called. The types don't match.
I've tried it with this little program:
...
main(!IO) :-
pstate(mkEntity("Das ist mein Text."), mkEncoding(utf8), init, !IO).
The result is like expected:
v.m:017: In clause for predicate `main'/2:
v.m:017: in argument 5 of call to predicate `parsing.pstate'/5:
v.m:017: type error: variable `STATE_VARIABLE_IO' has type
v.m:017: `io.state',
v.m:017: expected type was
v.m:017: `parsing.pstate(unit.unit)'.
So why on earth does it work in tryit.m ?
Cheers,
Volker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20220623/9a25cd63/attachment.sig>
More information about the users
mailing list