Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting duplicate record fields

Tags:

haskell

ghc

With -XDuplicateRecordFields, the following is allowed:

{-# LANGUAGE DuplicateRecordFields #-}

module Baz(Foo(..), Bar(..)) where
data Foo = Foo {qux :: Int}    
data Bar = Bar {qux :: String}

However, I get a compile error when Foo is defined in a module Foo and Bar is defined in a module Bar:

{-# LANGUAGE DuplicateRecordFields #-}

module Baz(Foo(..), Bar(..)) where
import Foo (Foo(..))
import Bar (Bar(..))

Conflicting exports for ‘qux’

I think what I'm trying to do is equivalent to the first example; it shouldn't matter where the data types are originally defined. Is this sort of thing supported in GHC 8?

like image 269
crockeea Avatar asked Oct 29 '22 11:10

crockeea


1 Answers

I did post a bug here. However, I also accidentally discovered a workaround:

If I put the pragma in either Foo.hs or Bar.hs, GHC accepts the program. That is, the following compiles:

{-# LANGUAGE DuplicateRecordFields #-}
module Foo(Foo(..)) where
data Foo = Foo {qux::Int}

module Bar(Bar(..)) where
data Bar = Bar {qux::String}

module Baz(Foo(..),Bar(..)) where
import Foo (Foo(..))
import Bar (Bar(..))
like image 181
crockeea Avatar answered Nov 15 '22 08:11

crockeea