[mercury-users] Status of unique modes in Mercury?

Edsko de Vries devriese at cs.tcd.ie
Fri Jul 4 20:03:32 AEST 2008


Hi,

> affected by the call) and nested uniqueness.  The compiler can, however,
> handle di/uo arguments fine, which is why IO is safe.

In what sense is it safe, though? Mercury allows me to duplicate the
world state, which is the one thing I would have thought should not be
possible:

:- module dup_unique.

:- interface.
:- import_module io.
:- pred main(io, io).
:- mode main(di, uo) is det.

:- implementation.
:- type pair(A,B) ---> mk_pair(A,B).

main(IOState_in, IOState_out) :-
  dup_unique(IOState_in, IO1, IO2),
  io.write_string("hello\n", IO1, _),
  io.write_string("world\n", IO2, IOState_out).

:- pred dup_unique(A,A,A).
:- mode dup_unique(
      unique
   >> clobbered,
      free
   >> unique,
      free
   >> unique) is det.
dup_unique(X,Y,Z) :- dup(mk_pair(X,1),Ps),
                     split(Ps,P1,P2),
                     fst(P1,Y),
                     fst(P2,Z).

:- pred dup(pair(A,int),pair(pair(A,int),pair(A,int))).
:- mode dup(
      bound(mk_pair(unique, ground)) 
   >> clobbered, 
      free 
   >> bound(mk_pair(bound(mk_pair(unique, ground)),
                    bound(mk_pair(unique, ground))))) is det.
dup(X,mk_pair(X,X)).

:- pred split(pair(A,B),A,B).
:- mode split(
      bound(mk_pair(bound(mk_pair(unique, ground)),
                    bound(mk_pair(unique, ground))))
   >> clobbered,
      free
   >> bound(mk_pair(unique, ground)),
      free
   >> bound(mk_pair(unique, ground))) is det.
split(mk_pair(X,Y),X,Y).

:- pred fst(pair(A,B),A).
:- mode fst(
      bound(mk_pair(unique, ground))
   >> clobbered,
      free
   >> unique) is det.
fst(mk_pair(X,_),X).

Edsko 
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list