[Haskell-cafe] Re: Status of TypeDirectedNameResolution proposal?

levi greenspan.levi at googlemail.com
Wed Nov 18 10:41:02 EST 2009


On Nov 18, 3:43 pm, Simon Peyton-Jones <simo... at microsoft.com> wrote:
> But anyway, the original TDNR thing is perfectly well defined. It might occasionally be surprising.  But that doesn't stop the OO folk from loving it.

Not only OO folks but I think anybody who works with many records
having similar selectors. In the past I had hopes for Daan Leijen's
"Extensible records with scoped labels" [1] to have some impact on
Haskell's record system but that didn't happen. Module-scoped
selectors + the fact that you need one file per module are just not
very convenient. Type classes only lead to more boilerplate in this
area. If I compare for instance:


data D1 = D1 { d1_p :: Int }
data D2 = D2 { d2_p :: Int }

class P a where
    p :: a -> Int
    withP :: a -> Int -> a

instance P D1 where
    p = d1_p
    withP p x = p { d1_p = x }

instance P D2 where
    p = d2_p
    withP p x = p { d2_p = x }


with the TDNR solution:


data D1 = D1 { p :: Int }
data D2 = D2 { p :: Int }


I have a clear preference. I think the important issue is not so much
that one can access p with OO-like notation, but that the scope of p
is effectively restricted. And very often one is not done with just
one type class but instead one writes many for the different record
fields. It was nice to see that DDC also has something similar to TDNR
[2]. I would be happy if someone corrects me and points out an easy
solution for this problem, but I fail to see one.

Cheers,
Levi


---
[1] http://legacy.cs.uu.nl/daan/pubs.html#scopedlabels
[2] http://www.haskell.org/haskellwiki/DDC/FieldProjections


More information about the Haskell-Cafe mailing list