[m-dev.] io__write and arrays

Fergus Henderson fjh at cs.mu.oz.au
Thu Apr 10 23:28:59 AEST 1997


Peter Schachte, you wrote:
> 
> > > For the purposes of discussion let's
> > > use the syntax #Typename{...}, where "Typename" could be any type name,
> > > and the interpretation of the "..." depends on the type.  For example, an
> > > integer array of 1, 2, and 3 might be written #array{1,2,3}.  This is
> > > ugly, but it'll do for discussion. 
> > 
> > I think that
> > 
> > 	uniq_array.from_list([1,2,3]) : uniq_array.uniq_array(int)
> > 
> > is less ugly.
> 
> It looks terribly verbose to me, making it more difficult to see what it
> means. It's disappointing to me that you can read a list of the first 3
> counting written as
> 
> 	[1,2,3]

Nope, that needs to be

	[1,2,3] : list.list(int)

(see below for why).

> but for an array of the first 3 counting numbers you have to write
> 
> 	uniq_array.from_list([1,2,3]) : uniq_array.uniq_array(int)

On further reflection, I realize that we could safely abbreviate this to

 	from_list([1,2,3]) : uniq_array.uniq_array(int)

Module qualifiers on the term are redundant, since we can
safely assume that they are implied by the type.

> and still not be able to read this in from a file.

No, the idea is that you would be able to read it in from a file.

> And why should you have to specify the int type for an array of ints?  You
> don't for a list of ints. 

Uh, actually you do have to specify the type.

Consider, for example, the type `lazy_list(int)', where lazy_list
is defined by

	:- type lazy_list(T)
		--->	[]
		;	[T | lazy_list(T)]
		;	lazy(pred(lazy_list(T))).

(see ~fjh/mercury/library/lazy_list.m for an elaboration of this idea).
What happens if you write out a lazy_list(int) and try to read it in again?
It had better have a type qualifier.

	[1,2,3] : lazy_list.lazy_list(int)

We could make `list' and `uniq_array' special cases, so that they do
not require type qualifiers... but is this worth it?  Hmm...
In fact that is not so easy, consider the following example:

	[no]

Does this have type `list(bool' or `list(maybe(int))'?
Consider this example too:

	[]

Does this have type `list(int)' or `list(float)' or
`list(the nameless type)' or what?
If the original value written out had type `list(int)', then
we need to write that out so that the type will be preserved when
we read it in again.

So we will have to explicitly type-qualify everything.

Note that if you are writing out large terms, the overhead of
writing out the type of the term is minimal.  For example:

	... very big term ... : hlds.module_info

Regarding module qualification, as pointed out above you only need to
module-qualify the type, there is no need to module-qualify the term.
Also, we could make the case where the module name and type name are the
same a special case, so that you don't need a module qualifier in that
case.

Finally, it might be better to use a different name for the array
constructor than `from_list', and as mentioned earlier we should
rename `uniq_array' as just `array'.

With all the above ideas taken into account, we would have

	[1,2,3] : list(int)

and

	array([1,2,3]) : array(int)

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



More information about the developers mailing list