Modular data-abstraction and mostly unique modes.
Henk Vandecasteele
Henk.Vandecasteele at cs.kuleuven.ac.be
Wed Jan 7 01:51:55 AEDT 1998
Hi,
I would like to build a finite domain solver. And given the
modules in Mercury I want to build an abstract type.
Unfortunately this seems incompatiable with Mostly unique modes.
One of data-structures I want to hide is the array I use to carry
all information and where I'd like to perform destrcutive update.
I can define an abstract type:
:- module fd_solver.
:- interface.
:- type fd_store.
and
:- implementation.
:- type fd_store == array(global_data)
But I cannot define modes without giving implementation details!
I would like to write:
:- module fd_solver.
:- interface.
:- import_module fstore.
:- type fd_store.
:- mode fd_store_muo :: free -> mostly_unique.
:- mode fd_store_mui :: mostly_unique -> mostly_unique.
:- mode fd_store_mdi :: mostly_unique -> mostly_dead.
But looking at the array_m?? I see this can better be:
:- module fd_solver.
:- interface.
:- import_module fstore.
:- type fd_store.
:- mode fd_store_muo :: free -> ground.
:- mode fd_store_mui :: ground -> ground.
:- mode fd_store_mdi :: ground -> mostly_dead.
Which I think is equivalent with:
% :- inst mostly_uniq_array(I) = mostly_unique(array(I)).
% :- inst mostly_uniq_array == mostly_uniq_array(mostly_unique).
:- inst mostly_uniq_array(I) = bound(array(I)). % XXX work-around
:- inst mostly_uniq_array == mostly_uniq_array(ground). % XXX
work-around
:- inst mostly_uniq_array_skel == mostly_uniq_array(free).
:- mode array_mdi == mdi(mostly_uniq_array).
:- mode array_muo == out(mostly_uniq_array).
:- mode array_mui == in(mostly_uniq_array).
Unfortunately Mercury doesn't find out this is the same!
I have to write:
:- module fd_solver.
:- interface.
:- import_module array.
:- type fd_store.
:- mode fd_store_muo :: array_muo.
:- mode fd_store_mui :: array_mui.
:- mode fd_store_mdi :: array_mdi.
Which I don't like.
Can anyone give me a hint how to do this?
Henk
More information about the users
mailing list