<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Hi cafe,</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">in my code I use Data.Data and OverlappingInstances. My problem now is, that I can't use functions using these instances as arguments for fromConstrM.</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">This is what my problem looks like:</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><blockquote style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255);margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:40px;border-top-style:none;border-right-style:none;border-bottom-style:none;border-left-style:none;border-width:initial;border-color:initial;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">
<div>{-# LANGUAGE FlexibleInstances #-}</div><div>{-# LANGUAGE OverlappingInstances #-}</div><div>{-# LANGUAGE UndecidableInstances #-}</div><div>import Data.Data</div><div><br></div><div>class Test a where</div><div> foo :: Monad m => m a</div>
<div> </div><div>instance Num a => Test a where</div><div> foo = return 1</div><div><br></div><div>instance Test Int where</div><div> foo = return 2</div><div><br></div><div>test constr = fromConstrM foo constr</div>
</blockquote><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
but when I compile I get:</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<div>test.hs:15:26:</div><div> Overlapping instances for Test d</div><div> arising from a use of `foo' at test.hs:15:26-28</div><div> Matching instances:</div><div> instance [overlap ok] (Num a) => Test a</div>
<div> -- Defined at test.hs:9:9-23</div><div> instance [overlap ok] Test Int -- Defined at test.hs:12:9-16</div><div> (The choice depends on the instantiation of `d'</div><div> To pick the first instance above, use -XIncoherentInstances</div>
<div> when compiling the other instance declarations)</div><div> In the first argument of `fromConstrM', namely `foo'</div><div> In the expression: fromConstrM foo constr</div><div> In the definition of `test': test constr = fromConstrM foo constr</div>
<div>Failed, modules loaded: none.</div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
Is there a way out? Right now I use a "case (typeOf x) of" kind of construct, but it gets pretty messy and I even have to unsafeCoerce at one point.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">- Timo</div>