[mercury-users] some [T] ...
Fergus Henderson
fjh at cs.mu.OZ.AU
Mon Nov 18 02:13:56 AEDT 2002
On 17-Nov-2002, Michael Day <mikeday at yeslogic.com> wrote:
>
> For the following type:
>
> :- type foo ---> some [T] foo(T) => bar(T).
>
> How will it be represented by the compiler? If not for the existential
> quantifier, presumably it would be a no-tag type. However does the
> existential quantifier mean that values of type foo are represented by a
> pointer to a cell containing two further pointers, one to the T and one to
> the type info for T?
Values of type foo are represented by a pointer to a cell containing two words.
The first word is the "typeclass_info" pointer, which records information
about the `foo(T)' instance, including the type_info for T and function
pointers for each of the methods of foo(T). The second word is the
value of type T. It is not necessarily a pointer.
Our paper on RTTI in Mercury [1] explains more of the details.
> Does the fact that there is a type class constraint
> on T affect the storage in any way,
Yes...
> for example by requiring an additional
> pointer to the type class method dictionary? Or is this referenced from
> the type info?
It's the other way around -- the type info is referenced from the
type class info.
> In this case, I am really looking for a value of a simple type (foo) and a
> simple inst (ground) that I can pass around that actually encapsulates a
> predicate via the type class methods. In some cases, this seems much more
> convenient than passing around a pred(...) and having to get all the modes
> right, which is basically impossible with the current compiler / library.
>
> However given that T will in many cases be a unit type carrying no
> information, it would be a shame to take three pointers when one would do.
> Any tips?
Another alternative is to pass around a func -- if the function has mode
func(in, in, ...) = out then in recent (ROTD) versions of Mercury you
can just use mode `in' or `out'.
References
[1] "Run time type information in Mercury".
Tyson Dowd, Zoltan Somogyi, Fergus Henderson, Thomas Conway and
David Jeffery.
Proceedings of the International Conference on the Principles and
Practice of Declarative Programming , Paris, France,
September/October 1999, Lecture Notes in Computer Science 1702,
Springer Verlag, Pages 224-243,
<http://www.cs.mu.oz.au/research/mercury/information/papers.html#rtti_ppdp>.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list