[m-dev.] record syntax

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Nov 29 09:39:19 AEDT 2000


On 28-Nov-2000, Peter Ross <peter.ross at miscrit.be> wrote:
> I think we should add the following to the record syntax for allowing
> the use of the record syntax for abstract types.
> 
> :- interface.
> 
> :- type abstract(T) with [field_a, field_b].
> 
> :- implementation.
> 
> :- type abstract(T)
>     --->    f(
>                 field_a :: int,
>                 field_b :: int,
>                 field_c :: int
>             ).
> 
> Any objections?

Yes: the interface needs to specify the field types.

Are you aware of the existing syntax for this?

	:- interface.

	:- type abstract(T).
	:- func field_a(abstract(T)) = int.
	:- func field_b(abstract(T)) = int.
	:- func field_c(abstract(T)) = int.
	:- func 'field_a:='(abstract(T), int) = int.
	:- func 'field_b:='(abstract(T), int) = int.
	:- func 'field_c:='(abstract(T), int) = int.

	:- implementation.

	:- type abstract(T)
	    --->    f(
			field_a :: int,
			field_b :: int,
			field_c :: int
		    ).

	% Note: no need to implement the functions declared in the interface

It's not as concise as it could, and it doesn't quite as clearly convey the
idea that `field_a', etc. are abstract fields of the abstract type,
but the effect is the same.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- 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