Overloaded record fields
Simon Peyton-Jones
simonpj at microsoft.com
Wed Jun 26 22:39:58 CEST 2013
| record projections. I would prefer to have dot notation for a
| general, very tightly-binding reverse application, and the type of the record
| selector for a field f changed to "forall r t. r { f :: t } => r -> t"
| instead of "SomeRecordType -> t". Such a general reverse application dot would
| allow things like "string.toUpper" and for me personally, it would
| make a Haskell OO library that I'm working on more elegant...
Actually I *hadn't* considered that. I'm sure it's been suggested before (there has been so much discussion), but I had not really thought about it in the context of our very modest proposal.
We're proposing, in effect, that ".f" is a postfix function with type "forall r t. r { f :: t } => r -> t". You propose to decompose that idea further, into (a) reverse function application and (b) a first class function f.
It is kind of weird that
f . g means \x. f (g x)
but f.g means g f
but perhaps it is not *more* weird than our proposal.
Your proposal also allows things like
data T = MkT { f :: Int }
foo :: [T] -> [Int]
foo = map f xs
because the field selector 'f' has the very general type you give, but the type signature would be enough to fix it. Or, if foo lacks a type signature, I suppose we'd infer
foo :: (r { f::a }) => [r] -> [a]
which is also fine.
It also allows you to use record field names in prefix position, just as now, which is a good thing.
In fact, your observation allows us to regard our proposal as consisting of two entirely orthogonal parts
* Generalise the type of record field selectors
* Introduce period as reverse function application
Both have merit.
Simon
| -----Original Message-----
| From: glasgow-haskell-users-bounces at haskell.org [mailto:glasgow-haskell-users-
| bounces at haskell.org] On Behalf Of Dominique Devriese
| Sent: 26 June 2013 13:16
| To: Adam Gundry
| Cc: glasgow-haskell-users at haskell.org
| Subject: Re: Overloaded record fields
|
| I think it's a good idea to push forward on the records design because
| it seems futile to hope for an ideal consensus proposal.
|
| The only thing I dislike though is that dot notation is special-cased to
| record projections. I would prefer to have dot notation for a
| general, very tightly-binding reverse application, and the type of the record
| selector for a field f changed to "forall r t. r { f :: t } => r -> t"
| instead of
| "SomeRecordType -> t". Such a general reverse application dot would
| allow things like "string.toUpper" and for me personally, it would
| make a Haskell OO library that I'm working on more elegant...
|
| But I guess you've considered such a design and decided against it,
| perhaps because of the stronger backward compatibility implications of
| changing the selectors' types?
|
| Dominique
|
| 2013/6/24 Adam Gundry <adam.gundry at strath.ac.uk>:
| > Hi everyone,
| >
| > I am implementing an overloaded record fields extension for GHC as a
| > GSoC project. Thanks to all those who gave their feedback on the
| > original proposal! I've started to document the plan on the GHC wiki:
| >
| > http://hackage.haskell.org/trac/ghc/wiki/Records/OverloadedRecordFields/Plan
| >
| > If you have any comments on the proposed changes, or anything is unclear
| > about the design, I'd like to hear from you.
| >
| > Thanks,
| >
| > Adam Gundry
| >
| > _______________________________________________
| > Glasgow-haskell-users mailing list
| > Glasgow-haskell-users at haskell.org
| > http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
|
| _______________________________________________
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users at haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
More information about the Glasgow-haskell-users
mailing list