Why not allow empty record updates?

Simon Peyton-Jones simonpj at microsoft.com
Mon Nov 14 23:09:40 CET 2011


Trouble is, what type does this have?

	f x = x {}

In your example the type annotations give the clue, but Haskell is mainly designed for type annotations to be optional.  We require at least one field so we can figure out, from the field name, which type is being updated.

Yes, something could doubtless be done by following the type annotations, much like higher-rank types, but it would be somewhat tricky to specify -- and the whole feature of type-changing update is (as you know) a bit obscure and not widely used, so it'd be adding complexity to an already-dark corner.  

See also the (inconclusive) discussion here, which would involve abolishing the entire type-changing update mechanism entirely!  http://hackage.haskell.org/trac/ghc/wiki/Records

Simon

|  -----Original Message-----
|  From: glasgow-haskell-users-bounces at haskell.org [mailto:glasgow-haskell-users-
|  bounces at haskell.org] On Behalf Of Herbert Valerio Riedel
|  Sent: 14 November 2011 14:31
|  To: glasgow-haskell-users at haskell.org
|  Subject: Why not allow empty record updates?
|  
|  Hello GHC HQ,
|  
|  I have been toying with phantom types in combination with "polymorphic"
|  record-updates (which is a great feature imho), but stumbled over a
|  limitation: GHC doesn't allow empty record updates (see toy example
|  below), and I couldn't find a GHC language extension to relax this
|  constraint. In the toy-example below it was easy to workaround by
|  performing a dummy record update, but for more advanced uses workarounds
|  becomes a bit more annoying.
|  
|  Is there a particular reason why empty record updates are disallowed by
|  the Haskell Report? Would it be sensible, to allow empty record updates
|  as a GHC language extension?
|  
|  
|  hvr.
|  
|  -------------------------------------------------------
|  -- empty types for tagging
|  data Clean
|  data Dirty
|  
|  data Foo a = Foo { fa :: Int, fb :: String }
|  data Bar a = Bar { ba :: Int, bb :: Foo a }
|  
|  markDirtyFoo :: Foo Clean -> Foo Dirty
|  markDirtyFoo foo = foo { } -- rejected with "Empty record update" error
|  markDirtyFoo foo = foo { fa = fa foo } -- workaround: dummy update
|  
|  markDirtyBar :: Bar Clean -> Bar Dirty
|  markDirtyBar bar = bar { bb = markDirtyFoo (bb bar) } -- works
|  
|  
|  
|  
|  
|  
|  _______________________________________________
|  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