[Haskell-cafe] Type Directed Name Resolution

Michael Snoyman michael at snoyman.com
Thu Nov 11 08:17:39 EST 2010

On Thu, Nov 11, 2010 at 2:24 PM, Lauri Alanko <la at iki.fi> wrote:
> On Thu, Nov 11, 2010 at 07:04:16PM +1030, John Lask wrote:
>> >>>it is often desirable to have the same field names
>> >>>for many records in the same module.
>> very much so, this is currently possible, with the restriction that
>> the field names must have the same type modulo the record it is
>> selecting on.
>> what is disirable is that this restriction be lifted.
> Why on earth? I thought that the motivation for this feature was
> simply to deal with naming conflicts with _unrelated_ records from
> _unrelated_ modules without having to resort to qualified names. But I
> can't see why someone would use the same accessor name for unrelated
> records in a single module. And if the records are related (and the
> field is conceptually "the same" for the records), then you can use a
> type class to overload the accessor name in a controlled fashion.
> So why would you ever need to reuse the same field name in the same
> module?

data PetOwner
data FurnitureOwner

data Cat = Cat { owner :: PetOwner }
data Chair = Chair { owner :: FurnitureOwner }

Just the first thing that came to mind, this kind of thing comes up
often enough to be an irritant. I'm not sure whether or not TDNR is a
good solution to the problem, just pointing out a use case.


More information about the Haskell-Cafe mailing list