[Haskell] Proposal: Allow "\=" for field update in record update syntax

Ben Rudiak-Gould Benjamin.Rudiak-Gould at cl.cam.ac.uk
Wed Mar 2 07:58:43 EST 2005

Benjamin Franksen wrote:

 >On Thursday 24 February 2005 23:27, Keean Schupke wrote:
 >>Well, not quite true, because the type of the label is used to index the
 >>value, the selection happens at compile time. So at run time there is no
 >>instance selection left... it is simply the value. At least in theory!
 >Hmm. I haven't seen it from this perspective, yet! At first reading, I 
 >this is simply too good to be true. I mean, there is some sort of list
 >structured thing representing the whole record, right? Then how can the
 >function that selects an element *not* traverse through the list?

It does. An HList of Int,Bool,Char is isomorphic to the type 
(Int,(Bool,(Char,()))), and selecting the Bool element will ultimately 
compile to code like this:

    case list of
      (_,(x,_)) -> ...

It doesn't need to search for the right element at runtime, and it 
doesn't need to check for end-of-list at runtime, but it does need to 
deconstruct O(n) pairs at runtime. A statically balanced tree structure 
would reduce that the O(log n), but I doubt it would improve performance 
for typical record sizes.

Of course, inlining may well lead to something like

    case (a,(b,(c,()))) of
      (_,(x,_)) -> ...

which can be optimized away.

-- Ben

More information about the Haskell mailing list