Proposal: FirstClassFieldUpdates
Jon Fairbairn
jon.fairbairn at cl.cam.ac.uk
Tue Jul 28 05:19:49 EDT 2009
Isaac Dupree
<ml at isaac.cedarswampstudios.org>
writes:
> Jon Fairbairn wrote:
>> Parenthesis around updates would make them into functions, ie
>> ({a=1,b=2,...}) would mean the same as (\d -> d{a=1,b=2,...}), but be
>> more concise.
>
> yes it is, however field updates are occasionally slightly
> annoying, since they can't change something's type at all,
> IIRC. Say,
> data C nx ny = C { x :: nx, y :: ny }
> x_set :: nx2 -> C nx1 ny -> C nx2 ny
> --x_set x2 c = c {x = x2} --type error
If that were the case, it would be a serious wart that needed to be
addressed. However, implementation would be fairly straightforward as
an "extension" is already present in ghc:
let x_set x2 c = c{x=x2}
:t x_set
x_set :: nx -> C t ny -> C nx ny
;-) (or did I misunderstand you?)
--
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
More information about the Haskell-prime
mailing list