[Haskell-beginners] question about shared data types

Ian Knopke ian.knopke at gmail.com
Mon Apr 29 12:28:03 CEST 2013


Hi everyone,

I have two modules that share a common data type in their respective data
structures:

package Aaa where

      newtype Foo = Foo String

      data Bar = Bar {
          barFoo :: [Foo]
      } deriving (Show, Eq)
      ...

package Bbb where

      newtype Foo = Foo String

      data Quux = Quux {
          quuxFoo :: [Foo]
      } deriving (Show, Eq)
      ...

Both modules require the Foo newtype defined. However, in all other
respects they are separate modules that can be used independently.

Defining the newtype Foo twice, as above, throws a compilation error
(ambigious reference). Importing one module inside another breaks
independence. I've been including newtype Foo in a Common.hs module that is
included in both, as I would in C or C++. This sort of thing can easily get
more complicated as the program grows however.

I was wondering if the Haskell community has a better solution to this that
I've overlooked.


Ian Knopke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130429/82edfcc7/attachment.htm>


More information about the Beginners mailing list