Skip to content

Implement record update for existential and GADT data types

Ganesh writes: The most important thing for me is supporting record update for existentially quantified data records, as in the error below.

In general I also find working with code that involves existential type variables quite hard work - for example I can't use foo as a record selector either, even if I immediately do something that seals the existential type back up again.

I don't understand this stuff well enough to be sure whether it's an impredicativity issue or not, though.

Foo.hs:11:8:
    Record update for the non-Haskell-98 data type `Foo' is not (yet)
supported
    Use pattern-matching instead
    In the expression: rec {foo = id}
    In the definition of `f': f rec = rec {foo = id}

Program is:

{-# LANGUAGE Rank2Types #-}
module Foo where

data Foo = forall a . Foo { foo :: a -> a, bar :: Int }

x :: Foo
x = Foo { foo = id, bar = 3 }

f :: Foo -> Foo
f rec = rec { foo = id }

g :: Foo -> Foo
g rec = rec { bar = 3 }

Simon says: Ah now I see. The relevant comment, TcExpr line 465, says

-- Doing record updates on
-- GADTs and/or existentials is more than my tiny 
-- brain can cope with today

Should be fixable, even with a tiny brain.

Trac metadata
Trac field Value
Version 6.8.3
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Unknown
Architecture Unknown
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information