<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div>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:<br></div><div><br></div><div>```<br></div><div>:- module store_experiment.<br></div><div><br></div><div>:- interface.<br></div><div>:- import_module io.<br></div><div><br></div><div>:- pred main(io::di, io::uo) is det.<br></div><div><br></div><div>:- implementation.<br></div><div>:- import_module store.<br></div><div><br></div><div>:- type simple_univ(S)<br></div><div>---><br></div><div>simple_univ(store(S)).<br></div><div><br></div><div>:- type simple_exist<br></div><div>---><br></div><div>some [S] simple_exist(S) => store(S).<br></div><div><br></div><div>:- pred init_simple_univ(simple_univ(S)) <= store(S).<br></div><div>init_simple_univ(SimpleU) :-<br></div><div>store.init(Store),<br></div><div>SimpleU = simple_univ(Store).<br></div><div><br></div><div>:- pred init_simple_exist(simple_exist).<br></div><div>init_simple_exist(SimpleE) :-<br></div><div>store.init(Store),<br></div><div>SimpleE = simple_exist(Store).<br></div><div><br></div><div>main(!IO) :-<br></div><div>init_simple_univ(SimpleUniv),<br></div><div>init_simple_exist(SimpleExist),<br></div><div>io.write_string(":)\n", !IO).<br></div><div>```<br></div><div><br></div><div>When I try to compile with `mmc -E --infer-all --make store_experiment`, I get the following error message:<br></div><div>```<br></div><div>store_experiment.m:022: In clause for predicate `init_simple_univ'/1:<br></div><div>store_experiment.m:022:   in unification of variable `SimpleU'<br></div><div>store_experiment.m:022:   and term `simple_univ(Store)':<br></div><div>store_experiment.m:022:   type error in argument of functor `simple_univ'/1.<br></div><div>store_experiment.m:022:   Argument 1 (Store) has type `(some [S]<br></div><div>store_experiment.m:022:   store.store(S))',<br></div><div>store_experiment.m:022:   expected type was `(some [S] store.store(S))'.<br></div><div>store_experiment.m:027: In clause for predicate `init_simple_exist'/1:<br></div><div>store_experiment.m:027:   in unification of variable `SimpleE'<br></div><div>store_experiment.m:027:   and term `simple_exist(Store)':<br></div><div>store_experiment.m:027:   type error in argument of functor `simple_exist'/1.<br></div><div>store_experiment.m:027:   Argument 1 (Store) has type `(some [S]<br></div><div>store_experiment.m:027:   store.store(S))',<br></div><div>store_experiment.m:027:   expected type was `(some [S] S)'.<br></div><div>```<br></div><div><br></div><div>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?<br></div><div><br></div><div>Thank you,<br></div><div>Patrick<br></div><div><br></div></body></html>