[mercury-users] some [T] ...
Ralph Becket
rafe at cs.mu.OZ.AU
Mon Nov 18 16:38:06 AEDT 2002
Fergus Henderson, Monday, 18 November 2002:
>
> The second and more serious issue is that values of sub-types can't be
> easily stored in and retrieved from the container types provided by
> the standard library, since the standard library routines for creating
> and accessing container types are not polymorphically moded. The Mercury
> compiler now supports polymorphic modes, so this issue could be solved
> by changing the standard library to use polymorphic modes. However,
> we have not yet done so, mainly because we have observed that doing so
> would significantly increase compilation time for programs that use the
> affected parts of the standard library (i.e. almost all programs).
Can't we leave the library alone and use it with subtypes if we adopt
the "implicit polymorphic modes" proposal. Mark and I discussed this
and came to the conclusion it was safe if we put big warning signs
around std_util__make_type and io__read stating that since the resulting
values may break various invariants assumed by the rest of the program
(because the operations allow us to break abstract types.) We could do
this if we had dynamic type class casts and a type class like
:- typeclass safely_constructable(T) where [
pred sanity_check(T),
mode sanity_check(in) is semidet
].
with the expectation that io__read etc. would complain if a read-in
value failed the sanity check (if any).
> However, the use of existentially quantified typeclass-constrained types
> as an alternative to passing higher-order values around directly solves
> both of these problems, and I believe it should have only a minor impact
> on efficiency compared to passing around higher-order values. This is
> IMHO a fairly elegant approach whose efficiency should be acceptable
> for most uses.
Agree pretty much.
> The one area in which there might be a major efficiency impact is that
> currently I think our optimizer probably does a better job of optimizing
> away higher-order code (i.e. converting it into first order code) than
> it does of optimizing away the use of typeclasses.
A SMOP!
- Ralph
--------------------------------------------------------------------------
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