[m-dev.] for review: cleanup of type_ctor_infos, part 0

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Mar 10 01:23:48 AEDT 2000


On 25-Feb-2000, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> 
> library/std_util.m:
> 	The predicates get_functor and construct take an integer argument
> 	that identifies a functor of a du type. The integer used to be
> 	the functor's ordinal number in the type definition, but this
> 	was not documented.

Well, it was documented, it's just that the documentation was
(unintentionally) unclear.

>	It is now the functor's position in the list
> 	of the type's functors sorted first on name and then on arity.
> 	This functionality is potentially more useful, since io__read
> 	could do binary instead of linear search when looking for a given
> 	functor. This is an incompatibility, but a very minor one.

I don't agree with that change.
The functionality that is being removed is IMHO important functionality,
and while the functionality that is being added in its place may be useful
too, it doesn't make up for the loss of functionality.
If you want a version that returns the position in the lexicographic ordering,
that's fine, so long as the version which returns the position in the
declaration ordering still remains.

For example, one thing that you can do with the old version is
to serialize Mercury terms into binary data, using index/2
and deconstruct/4, and then deserialize them using
construct/3.  With the new version, this is not possible.
You'd have to use deconstruct/4 and then get_functor/5 instead of
index/2, which would be considerably less efficient.

Another piece of functionality missing is the ability to convert an ordinal
value to its corresponding enumeration value in some enumeration type, in a
type-safe manner.  Note that many languages, including Haskell, Pascal and
Ada, provide a way to do this.  As soon as you want to do things like
representing enumeration sets using bit vectors, you need to be able
to do this.

-- 
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 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list