[mercury-users] "some" and existential types

Michael Day mikeday at corplink.com.au
Sun Oct 3 00:25:23 AEST 1999


> and says that give_me_a_value2/1 will provide a value of *some* type, but
> it won't tell you what that type is.  So you (the caller) have to be
> prepared
> to handle *any* type that comes back.  Basically, it's a constraint that the
> caller be polymorphic rather than the callee.

Right, thanks! That appears to be the concept I was having trouble
wrapping my head around, I couldn't see the difference between the two
types of polymorphism. Just to shift focus for a second to the caller, how
exactly do you demand a particular return type? Would this work:

% no references to "X" before this point...

	give_me_a_value(X),
	(
		X = [],
		...
	;
		X = [A|As],
		...
	),

I'm hoping that would constrain give_me_a_value to return a list, but I
should play around with some actual code before I make a bigger fool of
myself...

If give_me_a_value is declared for some [T], then attempting to constrain
it to a list would create semidet code that would not necessarily succeed?

<somewhat overlarge snip>

> Hope this helps,
> 
> Ralph

Indeed, a very very informative post, thank you kindly! It occurs to me
that you've practically written a new chapter for your tutorial in
replying, perhaps worth putting on the web so you can just refer the
desperately unenlightened to an appropriate url? :)

Looking at existential types from a purely syntactical perspective I
initially felt that the "some [T]" should be optional when in the presence
of typeclass constraints. In retrospect I see that I did not at that point
understand what existential types actually were, and thus I withdraw my
dubious quibbles.

Michael

(One final jab at C++, I was referring earlier to the fact that you can't
overload by return type, because there is no way for the caller to place
constraints on the type of a returned value. Annoying, as I'm sure it
could have been added with some horrendous abuse of casting syntax.
Anyway, nice to be able to do things the Right Way at last).


--------------------------------------------------------------------------
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