[mercury-users] Circular lists
fjh at cs.mu.oz.au
Thu Dec 4 19:02:02 AEDT 1997
Warwick HARVEY <warwick at cs.mu.oz.au> wrote:
> Please let me check my understanding here. I think it may spell trouble for
> me and the program I'm writing. :-) (Well, at the very least, my data may
> need restructuring).
> When existential types are implemented, will each store be *required* to
> have a distinct type?
> What I'm currently trying to implement involves
> (essentially) a store of stores. If each store is forced to have a
> different type, there is no way I can form a collection of them.
Currently that is true, but when we have support for existential types,
you will be able to use them to create heterogenous collections.
So, existential types might introduce a problem, but they also
provide a solution to that problem.
> I can get
> around this by reorganising my data structures, but I'd rather avoid this at
> this stage if I can.
Yes, there should be no need to reorganize your data structure.
> At the moment I'm running afoul of the type system, because when I started
> I didn't really understand what the parameter S for stores was, or what it
> was for. Everything I've written has stores parameterised in this way. The
> problem I have is that when I create a new store to insert into the main
> store, store__init/1 says the type is store(some_store_type), while my
> predicate advertises itself as working on general store(S). To fix this, I
> will basically have to replace all occurrences of S with some_store_type
> throughout my code, and it will all break when existential types are added.
If a predicate takes a store as an input argument,
then you should use a (universal) polymorphic type, i.e. `S'.
If a predicate creates a store using store__init/1 and returns it
as an ouput argument, then ideally you should use an existential polymorphic
type; but in the absence of existential types, you should probably
In other words, to minimize future problems, you should replace *some*
of the occurrences of `S' with `some_store_type' -- as few as possible.
If you do this, then it should be possible to make your code work
when we have support for existential types with only minor changes
e.g. probably something along the lines of replacing
`:- pred p(..., some_store_type, ...)' with
`:- some [S] pred p(..., S, ...).'
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 18.104.22.168 | -- the last words of T. S. Garp.
More information about the users