[clean-list] Selecting record fields with same names

Maarten de Mol maartenm@cs.kun.nl
Mon, 11 Feb 2002 09:09:56 +0100


>
> From: "Maarten de Mol" <maartenm@cs.kun.nl>
> >
> > You can have the same field names in different records. However, as you
> > already found out, you sometimes have to specify explicitly which record
> > type the field name belongs to. In this case, the function appendStrings
> > can be fixed as follows:
> >
> >    appendStrings :: Rec1 Rec2 -> String
> >    appendStrings r1 r2 = r1.Rec1.s +++ r2.Rec2.s
> >                             ^^^^          ^^^^
> >
> > I don't know exactly why the compiler isn't able to figure this out
> > itself (although I have run into this several times myself); it has
> > something
> > to do with the typing algorithm I'm sure.
>
> I was told that this is not necessarily the typing algorithms fault, but
> more the moment at which typing takes place, and the information it has at
> its disposal at that moment.

Yes. But the real question is: WHY is this information not available to
the typing algorithm at the time?

By the way, I wasn't implicating the typing algorithm ;-)

>
> It is a pain sometimes, and it does seems rather dumb when you hit this
> problem. Try to explain this to a 'imperative' programmer and (s)he will
> have to suppress a smile.

Luckily, 'we' sometimes have to suppress a smile when looking at
'imperative' algorithms.

>
> Marco Kesseler
>
>

Maarten de Mol