[m-users.] Why can't there be multiple field constructor field names in the same module?

Philip White philip at pswhite.org
Tue Oct 19 09:10:03 AEDT 2021


On Thu, 14 Oct 2021 12:55:08 +1100
Peter Wang <novalazy at gmail.com> wrote:

> On Thu, 14 Oct 2021 12:34:02 +1100 "Zoltan Somogyi"
> <zoltan.somogyi at runbox.com> wrote:
> > 
> > 2021-10-14 11:55 GMT+11:00 "Philip White" <philip at pswhite.org>:  
> > > I'm getting an error like "field abc multiply defined" for type
> > > definitions like the following:
> > > 
> > > :- type x ---> x(abc :: int).
> > > :- type y ---> y(abc :: int).
> > > 
> > > The error is quite clear, so I'm not confused what it's
> > > complaining about; I'm just confused *why*. Is there a
> > > fundamental reason that having fields with the same name in the
> > > same module is unacceptable, or has no one yet implemented
> > > support for it?  
> >   
> 
> The requirement for field names to be unique within a module was
> lifted as of ROTD 2021-05-07 or so.
> 
> However, it is still not allowed to declare field getter/setter
> functions for multiple fields of the same name in the same module,
> e.g.
> 
>     :- func abc(x) = int.
>     :- func abc(y) = int.
> 
> Peter

Thanks for the clear explanations, both of you. I had been under the
impression that Mercury supported full overloading of function names,
but it looks like that just means there can be multiple
functions/predicates of the same name in scope, but they still have to
have different fully-qualified names.


More information about the users mailing list