<div>
                    The problem is that your definition of arbitrary for the Building instance isn’t indented under the ‘instance Arbitrary Building’, so it’s getting interpreted as two top-level statements: one that Building is an Arbitrary of Instance, and one that defines a value named ‘arbitrary’. Hence the error message. To fix this, just indent the definition of arbitrary like you did in the Glass definition.</div>
                <div></div>
                 
                <p style="color: #A0A0A8;">On Tuesday, November 26, 2013 at 11:06 AM, Kees Bleijenberg wrote:</p>
                <blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
                    <span><div><div><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"><meta name="Generator" content="Microsoft Word 12 (filtered medium)"><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--><div><p style="margin: 0px;">I have a Building with a field glass: Glass.<o:p></o:p></p><p style="margin: 0px;">I want to use quickcheck. Therefor I wrote a TestGlass.hs with the Arbitrary instance declaration for Glass. I also want to make Building an instance of Arbitrary. For the field glass in the Building I need the arbitrary :: Gen Glass function out of TestGlass.hs.<o:p></o:p></p><p style="margin: 0px;">How do I export and use the instance declarations from TestGlass.hs?<o:p></o:p></p><p style="margin: 0px;"><o:p> </o:p></p><p style="margin: 0px;">Glass.hs<o:p></o:p></p><p style="margin: 0px;">module Glass(<o:p></o:p></p><p style="margin: 0px;">    Glass(..))<o:p></o:p></p><p style="margin: 0px;">where<o:p></o:p></p><p style="margin: 0px;">data Glass = Glass Int<o:p></o:p></p><p style="margin: 0px;"><o:p> </o:p></p><p style="margin: 0px;">TestGlass.hs<o:p></o:p></p><p style="margin: 0px;">module TestGlass()<o:p></o:p></p><p style="margin: 0px;">where<o:p></o:p></p><p style="margin: 0px;">import Test.QuickCheck<o:p></o:p></p><p style="margin: 0px;">import Test.QuickCheck.Gen<o:p></o:p></p><p style="margin: 0px;">import Glass<o:p></o:p></p><p style="margin: 0px;"><o:p> </o:p></p><p style="margin: 0px;">instance Arbitrary Glass where<o:p></o:p></p><p style="margin: 0px;">    arbitrary = do<o:p></o:p></p><p style="margin: 0px;">                    n <- choose (1,8) :: Gen Int <o:p></o:p></p><p style="margin: 0px;">                    return $ Glass n<o:p></o:p></p><p style="margin: 0px;"><o:p> </o:p></p><p style="margin: 0px;"><o:p> </o:p></p><p style="margin: 0px;">Building.hs<o:p></o:p></p><p style="margin: 0px;">module Building ()<o:p></o:p></p><p style="margin: 0px;">where<o:p></o:p></p><p style="margin: 0px;">import Glass<o:p></o:p></p><p style="margin: 0px;">import TestGlass<o:p></o:p></p><p style="margin: 0px;">import Test.QuickCheck<o:p></o:p></p><p style="margin: 0px;">import Test.QuickCheck.Gen<o:p></o:p></p><p style="margin: 0px;"><o:p> </o:p></p><p style="margin: 0px;">data  Building = Building {<o:p></o:p></p><p style="margin: 0px;">                                glass :: Glass<o:p></o:p></p><p style="margin: 0px;">                              }<o:p></o:p></p><p style="margin: 0px;">instance Arbitrary Building where<o:p></o:p></p><p style="margin: 0px;">arbitrary = do <o:p></o:p></p><p style="margin: 0px;">                g <- arbitrary :: (Gen Glass)<o:p></o:p></p><p style="margin: 0px;">                return Building { glass = g}<o:p></o:p></p><p style="margin: 0px;"><o:p> </o:p></p><p style="margin: 0px;"><o:p> </o:p></p><p style="margin: 0px;">When I compile Building I get:<o:p></o:p></p><p style="margin: 0px;"><span style="font-size:9.0pt;font-family:Consolas;color:#AF0000">Building.hs:13:23:<o:p></o:p></span></p><p style="margin: 0px;"><span style="font-size:9.0pt;font-family:Consolas;color:#AF0000">    Ambiguous occurrence `arbitrary'<o:p></o:p></span></p><p style="margin: 0px;"><span style="font-size:9.0pt;font-family:Consolas;color:#AF0000">    It could refer to either `Building.arbitrary',<o:p></o:p></span></p><p style="margin: 0px;"><span style="font-size:9.0pt;font-family:Consolas;color:#AF0000">                             defined at Building.hs:12:1<o:p></o:p></span></p><p style="margin: 0px;"><span style="font-size:9.0pt;font-family:Consolas;color:#AF0000">                          or `Test.QuickCheck.arbitrary',<o:p></o:p></span></p><p style="margin: 0px;"><span style="font-size:9.0pt;font-family:Consolas;color:#AF0000">                             imported from `Test.QuickCheck' at Building.hs:5:1-22<o:p></o:p></span></p><p style="margin: 0px;"><span style="font-size:9.0pt;font-family:Consolas;color:#AF0000">                             (and originally defined in `Test.QuickCheck.Arbitrary')<o:p></o:p></span></p><p style="margin: 0px;"><o:p> </o:p></p><p style="margin: 0px;">It looks like the compiler doesn’t look at the instance declarations in the TestGlass module.<o:p></o:p></p><p style="margin: 0px;">What is wrong in my code?<o:p></o:p></p><p style="margin: 0px;">I want to split the testcode as much as possible from the non-test code and I don’t want to merge the modules Building and Glass (they are both already big).<o:p></o:p></p><p style="margin: 0px;"><o:p> </o:p></p><p style="margin: 0px;">Kees<o:p></o:p></p><p style="margin: 0px;"><o:p> </o:p></p></div></div><div><div>_______________________________________________</div><div>Haskell-Cafe mailing list</div><div><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a></div><div><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a></div></div></div></span>
                 
                 
                 
                 
                </blockquote>
                 
                <div>
                    <br>
                </div>