Hi,<div><br></div><div>I'm running in errors that, I think, is related with functional dependence. But I don't know how to interpret or solve them.</div><div><br></div><div>I have basically 3 types: Edge, Face and Simplex (Tetrahedron) and I want to combined them in a class type such that: </div>
<meta http-equiv="content-type" content="text/html; charset=utf-8"><div> - Edge and Face will produce a convex hull</div><div> - Face and Simplex will produce a Delaunay triangulation</div><div>under the same MCB (Marriage Before Conquer) algorithm.</div>
<div><br></div><div>I first tried to use Multiparameter type class with functional dependence relation:</div><div><br></div><div><div>class SubUnit subUnit unit | subUnit -> unit, unit -> subUnit where</div><div> buildUnit :: ActiveSubUnit subUnit -> [Point] -> Maybe unit</div>
<div> build1stUnit :: Plane -> [Point] -> [Point] -> [Point] -> Maybe unit</div><div> getAllSubUnits :: unit -> [ActiveSubUnit subUnit]</div><div> subUnitPos :: BoxPair -> subUnit -> Position</div>
</div><div><br></div><div><br></div><div>but then I decide to go for a GADT form (If someone wants to try to compile it, one can get the complete code on GitHub: <a href="http://github.com/EdgarGomes/DeUni">http://github.com/EdgarGomes/DeUni</a>) :</div>
<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><div><br></div><div>class SubUnit subUnit where</div><div> type Unit subUnit :: *</div><div> buildUnit :: ActiveSubUnit subUnit -> [Point] -> Maybe (Unit subUnit)</div>
<div> build1stUnit :: Plane -> [Point] -> [Point] -> [Point] -> Maybe (Unit subUnit)</div><div> getAllSubUnits :: Unit subUnit -> [ActiveSubUnit subUnit]</div><div> subUnitPos :: BoxPair -> subUnit -> Position</div>
</div><div><br></div><div><br></div><div><br></div><div><br></div><div>In both cases I get a couple of errors like:</div><div><br></div><div><div>src/DeUni.hs:265:39:</div><div> Couldn't match type `Unit subUnit3' with `Unit subUnit2'</div>
<div> NB: `Unit' is a type function, and may not be injective</div><div> Expected type: Unit a</div><div> Actual type: Unit subUnit2</div><div> In the expression: un</div><div> In the expression: [un]</div>
<div> In the first argument of `return', namely</div><div> `(([un], fromList $ getAllSubUnits un) ::</div><div> SubUnit a => ([Unit a], SetActiveSubUnits a))'</div><div><br></div><div>src/DeUni.hs:265:39:</div>
<div> Couldn't match type `Unit (ActiveSubUnit subUnit3)'</div><div> with `Unit subUnit2'</div><div> NB: `Unit' is a type function, and may not be injective</div><div> Expected type: Unit a</div>
<div> Actual type: Unit subUnit2</div><div> In the expression: un</div><div> In the expression: [un]</div><div> In the first argument of `return', namely</div><div> `(([un], fromList $ getAllSubUnits un) ::</div>
<div> SubUnit a => ([Unit a], SetActiveSubUnits a))'</div><div><br></div><div>src/DeUni.hs:265:44:</div><div> Could not deduce (a1 ~ ActiveSubUnit subUnit3)</div><div> from the context (SubUnit a)</div>
<div> bound by the type signature for</div><div> mbc :: SubUnit a =></div><div> [Point] -> SetActiveSubUnits a -> Box -> StateMBC a [Unit a]</div><div> at src/DeUni.hs:(260,1)-(317,53)</div>
<div> or from (SubUnit a1)</div><div> bound by an expression type signature:</div><div> SubUnit a1 => ([Unit a1], SetActiveSubUnits a1)</div><div> at src/DeUni.hs:265:37-117</div><div> `a1' is a rigid type variable bound by</div>
<div> an expression type signature:</div><div> SubUnit a1 => ([Unit a1], SetActiveSubUnits a1)</div><div> at src/DeUni.hs:265:37</div><div> Expected type: SetActiveSubUnits a</div><div>
Actual type: Set (ActiveSubUnit subUnit3)</div><div> In the expression: fromList $ getAllSubUnits un</div><div> In the first argument of `return', namely</div><div> `(([un], fromList $ getAllSubUnits un) ::</div>
<div> SubUnit a => ([Unit a], SetActiveSubUnits a))'</div></div><div><br></div><div>.....</div><div>.....</div><div><br></div><div><br></div><div>Any help is more than welcome!</div><div><br></div><div>Cheers,</div>
<div>Edgar Gomes (LambdaSteel)</div>