Dear Stephan,<div><br></div><div>Finally!!!! It's alive and working, huhhuu! After 3 long days...</div><div><br></div><div>As predictable, it was my fault. There was basically two big mistakes:</div><div><br></div><div>
- splitAF::(SubUnit a b, Ord a)=>BoxPair -> ActiveSubUnit a -> StateMBC a ()</div><div>instead of "splitAF::(SubUnit a, Ord a)=> BoxPair -> a -> StateMBC a ()"</div><div><br></div><div>- type SetActiveSubUnits a = Set (ActiveSubUnit a)</div>
<div>instead of "type SetActiveSubUnits a = Set a"</div><div><br></div><div>After those corrections there was one error remaining:</div><div><br></div><div><div>src/DeUni.hs:264:39:</div><div> Could not deduce (Unit a ~ Unit subUnit0)</div>
<div> from the context (SubUnit a, Ord a)</div><div> bound by the type signature for</div><div> mbc :: (SubUnit a, Ord a) => [Point] -> SetActiveSubUnits a -> Box -> StateMBC a [Unit a]</div>
<div> at src/DeUni.hs:(253,1)-(310,53)</div><div> NB: `Unit' is a type function, and may not be injective</div><div> Expected type: [Unit a]</div><div> Actual type: [Unit subUnit0]</div></div><div><br>
</div><div>Then I decided to go back to Fun Dep instead of GADT due the "injective" complain.</div><div><br></div><div>class SubUnit subUnit unit | subUnit -> unit, unit -> subUnit where</div><div> .....</div>
<div><br></div><div>instead of</div><div><div><br></div><div>class SubUnit subUnit where</div><div> type Unit subUnit :: *</div></div><div> .....</div><div><br></div><div>And ... Bingo!</div><div><br></div><div>My last question, how can I make it work using GADT?</div>
<div><br></div><div>Thank so much for your kindly assistance.</div><div><br></div><div>Edgar</div><div><br></div><div><br><br><div class="gmail_quote">On 26 March 2011 23:13, Stephen Tetley <span dir="ltr"><<a href="mailto:stephen.tetley@gmail.com">stephen.tetley@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi Edgar<br>
<br>
I think you have some errors of construction rather than just a<br>
problem with the type families / fun deps.<br>
<br>
Note, I've knocked off the class constraints on the data declarations<br>
on the copy I'm working with (e.g ActiveSubUnit) , this may or may not<br>
change things.<br>
<br>
This change to splitAF will type check, whether or not it does what you want:<br>
<br>
> splitAF::(SubUnit a, Ord a)=> BoxPair -> a -> StateMBC a ()<br>
> splitAF pairBox e = case subUnitPos pairBox e of<br>
<br>
<br>
Your code was:<br>
<br>
> splitAF::(SubUnit a)=>BoxPair -> a -> StateMBC a ()<br>
> splitAF pairBox e = case subUnitPos pairBox (activeUnit e) of<br>
<br>
<br>
getUnitsOnPlane will compile if you comment out the type sig, but GHC<br>
generates this type sig:<br>
<br>
<br>
getUnitsOnPlane ::<br>
(Unit su1 ~ Unit su,<br>
SubUnit (ActiveSubUnit su),<br>
SubUnit su1,<br>
SubUnit su,<br>
Ord su) =><br>
[Point]<br>
-> BoxPair<br>
-> t<br>
-> StateT<br>
(SubUnitsSets (ActiveSubUnit su))<br>
Data.Functor.Identity.Identity<br>
[Unit su]<br>
-- Defined at DeUni.hs:324:1-15<br>
<br>
Note the class constraints are introducing a type variable *su1* that<br>
isn't mentioned in the function arguments, this strongly makes me<br>
think the function body isn't doing what it should. Also GHC infers a<br>
type var *t* rather than Plane for the second arg, again this makes me<br>
think the function body is not right.<br>
<br>
I'm a bit at a loss with the mbc function, if I comment out the<br>
function type sig and local type sigs GHC generates some errors<br>
mentioning Edge - as Edge is one of the instances of SubUnit, I think<br>
the function body is less polymorphic than you expect.<br>
<div><div></div><div class="h5"><br>
Best wishes<br>
<br>
Stephen<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div>