Records in Haskell
nhn at Cs.Nott.AC.UK
Sat Feb 11 17:59:41 CET 2012
Greg Wever wrote:
> What is the use case for changing the type of a record field on
For example, I often use in the context of abstract syntax parametrised
on the type of some kind of "annotation". A transformation may then
take an abstract syntax tree with one type of annotation onto an
abstract syntax tree with a different type of annotation. And if I
opted to use named fields for my abstract syntax tree nodes, as I tend
to do, polymorphic record update is exactly what I need.
> This seems to make things harder on the implementer and harder on
> users to reason about the types in their program.
Can't comment on the former, but I don't find the latter compelling.
I find it completely natural and in a well-documented program there
will be enough explicit type information around to make it pretty clear
what is going on.
> I think it would be easier on everyone to just remove this capability
I'd say that would be very unfortunate.
> or have an explicit syntax for changing the type to make it easier
> for both implementer (to distinguish) and user (to declare intent).
Also sounds unfortunate, and might lead to very repetitive code?
I have not followed this thread close enough to be able to say for
sure, but if the upshot is that code like the one I am alluding to
above would need an annotation wherever there is a polymorphic record
update today, then that would not be very nice.
For all its flaws, the present Haskell "record" system is far from as
useless as it sometimes is made out to be, and it would be a pity
if the price for fixing some of those flaws were to lose something
as useful as update of polymorphic record fields.
School of Computer Science
The University of Nottingham
nhn at cs.nott.ac.uk
More information about the Glasgow-haskell-users