[m-users.] Store type difficulties

Patrick Henning pjhenning at fastmail.com
Sat Jul 4 09:47:28 AEST 2020


Hello, I am trying to incorporate mutvars into a program but have encountered some type errors I don't understand. The ultimate goal is to have a type which collects values and can allow mutable updates to these values, so what I would like is to structure the type with a mutvar store to hold the values and a list to keep track of the mutvars. As a first step towards understanding, I put together a small sketch program with the following contents:

```
:- module store_experiment.

:- interface.
:- import_module io.

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

:- implementation.
:- import_module store.

:- type simple_univ(S)
--->
simple_univ(store(S)).

:- type simple_exist
--->
some [S] simple_exist(S) => store(S).

:- pred init_simple_univ(simple_univ(S)) <= store(S).
init_simple_univ(SimpleU) :-
store.init(Store),
SimpleU = simple_univ(Store).

:- pred init_simple_exist(simple_exist).
init_simple_exist(SimpleE) :-
store.init(Store),
SimpleE = simple_exist(Store).

main(!IO) :-
init_simple_univ(SimpleUniv),
init_simple_exist(SimpleExist),
io.write_string(":)\n", !IO).
```

When I try to compile with `mmc -E --infer-all --make store_experiment`, I get the following error message:
```
store_experiment.m:022: In clause for predicate `init_simple_univ'/1:
store_experiment.m:022: in unification of variable `SimpleU'
store_experiment.m:022: and term `simple_univ(Store)':
store_experiment.m:022: type error in argument of functor `simple_univ'/1.
store_experiment.m:022: Argument 1 (Store) has type `(some [S]
store_experiment.m:022: store.store(S))',
store_experiment.m:022: expected type was `(some [S] store.store(S))'.
store_experiment.m:027: In clause for predicate `init_simple_exist'/1:
store_experiment.m:027: in unification of variable `SimpleE'
store_experiment.m:027: and term `simple_exist(Store)':
store_experiment.m:027: type error in argument of functor `simple_exist'/1.
store_experiment.m:027: Argument 1 (Store) has type `(some [S]
store_experiment.m:027: store.store(S))',
store_experiment.m:027: expected type was `(some [S] S)'.
```

I am struggling to understand how to properly describe the container type since neither the existentially nor universally type version seems to work. Can anyone recommend how to do this correctly?

Thank you,
Patrick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20200703/43b16220/attachment.html>


More information about the users mailing list