[clean-list] Selecting record fields with same names

Marco Kesseler m.kesseler@aia-itp.com
Mon, 11 Feb 2002 09:01:30 +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.

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.

Marco Kesseler