[Haskell-beginners] question about shared data types

David Virebayre dav.vire+haskell at gmail.com
Mon Apr 29 13:44:47 CEST 2013


What about making a third module that defines and exports Foo ?

David.


2013/4/29 Ian Knopke <ian.knopke at gmail.com>

> 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
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130429/14065a3b/attachment.htm>


More information about the Beginners mailing list