Why not allow empty record updates?

Simon Peyton-Jones simonpj at microsoft.com
Wed Nov 16 10:07:48 CET 2011

| >>>>>> Trouble is, what type does this have?
| >>>>>>   f x = x {}
| >>	
| >> Malcolm Wallace wrote:
| >>>>> f :: a ->  a
| >>
| >> Ian Lynagh wrote:
| >>>> That wouldn't help the original poster, as it is incompatible with
| >>>> f :: Foo Clean ->  Foo Dirty

There are several different things going on in this thread.

1.  What does  f x = x {} mean?  The report http://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-490003.15 says we should treat it like  
   f x = case x of
           C1 a b -> C1 a b
           C2 v -> C2 v
but if there are no fields how do we know what C1 and C2 are?  The whole section only makes sense if you know x's type.  So Malcolm's suggestion of "f :: forall a. a -> a" would be non-uniform with the non-empty cases.

When we *do* know the type then the above translation makes sense, and even allows the
	f :: Foo Clean -> Foo Dirty
type-change.  Now two further issues arise:

2. When do we "know the type"?  If the type is supposed to come from an enclosing type signature, to specify the type system one would need to specify the way that type annotations propagate. This isn't impossible (we do it for higher-rank types), but it seems like a big hammer for this particular nut.

3.  Edward wants to maintain sharing, meaning presumably that no fresh record is allocated.  That makes sense, but sadly System FC (GHC's intermediate language) has no way to express it.  We'd need some new axioms claiming that   forall ab. Foo a ~ Foo b.  But that's a question for another time.  Moreover, it affects non-record types just as much.


More information about the Glasgow-haskell-users mailing list