[mercury-users] restriction on typeclass instances
David Glen JEFFERY
dgj at students.cs.mu.oz.au
Sat May 20 14:33:09 AEST 2000
On 15-Nov-1999, Mark Anthony BROWN <dougl at cs.mu.OZ.AU> wrote:
>
> If you change the definition of `thing' to
>
> :- type thing(T) ---> thing(T).
>
> then your example should compile OK (and not throw unexpected exceptions).
> This has worked for me the one or two times I have needed it,
> though I'm not claiming it will always work.
> [...]
>
> So, I agree that the restriction *could* be a pain, but I'm not
> convinced. Can anyone think of an example where this work-around
> would not be adequate to overcome the restriction?
I'm prety sure the scheme you've described will always work, however there
are times when it can be a considerable pain. For example, you may need to
apply the `thing' functor to all the elements in your data structure, which
could mean having to write extra traversal code. It *may* even be the case
that the compiler has trouble optimising away the traversal.
eg. Would the compiler be able to optimise this:
list__map((pred(A::in, B::out) is det :- B = thing(A)), Xs, Ys)
into this:
Xs = Ys
(In this case I think it would, but I imagine that there are more complicated
cases that it might not catch).
dgj
--
David Jeffery (dgj at cs.mu.oz.au) | If your thesis is utterly vacuous
PhD student, | Use first-order predicate calculus.
Dept. of Comp. Sci. & Soft. Eng.| With sufficient formality
The University of Melbourne | The sheerist banality
Australia | Will be hailed by the critics: "Miraculous!"
| -- Anon.
--------------------------------------------------------------------------
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