Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell: Record Update for Existential Types

I was trying to use record update for an existential record when I ran into an error. A quick google led me to feature request #2595, which shows it as implemented for GHC back in version 6.8.3. I'm using 6.10.4, so I'd think it should work, but the example code from the feature request:

{-# LANGUAGE ExistentialQuantification,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 } 

yield the same errors as complained of in the feature request:

test.hs:10: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}

test.hs:13:8:
    Record update for the non-Haskell-98 data type `Foo' is not (yet) supported
    Use pattern-matching instead
    In the expression: rec {bar = 3}
    In the definition of `g': g rec = rec {bar = 3}

Was this a consciously dropped feature at some point, or should I file a bug report?

like image 447
rampion Avatar asked Jan 02 '11 20:01

rampion


2 Answers

Actually, the Trac slip says it was implemented in version 6.12 — the bug was found in version 6.8.3. So you're using a version that's older than the fix.

Also, the changelog entry for the fix seems to indicate that it's not completely fixed; you'd still be getting the first error, just not the second. If there isn't already a bug report for the rest of the problem, I'd say go ahead and file.

like image 177
Luke Maurer Avatar answered Sep 24 '22 00:09

Luke Maurer


There is still another way!


If you change the data type definition from

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

to

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

, then it compiles without error. -- using ghc-6.12.2.20100531

like image 44
comonad Avatar answered Sep 23 '22 00:09

comonad