Hi,<div><br></div><div>I&#39;m running in errors that, I think, is related with functional dependence. But I don&#39;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 -&gt; unit, unit -&gt; subUnit where</div><div>    buildUnit      :: ActiveSubUnit subUnit -&gt; [Point] -&gt; Maybe unit</div>
<div>    build1stUnit   :: Plane -&gt; [Point] -&gt; [Point] -&gt; [Point] -&gt; Maybe unit</div><div>    getAllSubUnits :: unit -&gt; [ActiveSubUnit subUnit]</div><div>    subUnitPos     :: BoxPair -&gt; subUnit -&gt; 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 -&gt; [Point] -&gt; Maybe (Unit subUnit)</div>
<div>    build1stUnit   :: Plane -&gt; [Point] -&gt; [Point] -&gt; [Point] -&gt; Maybe (Unit subUnit)</div><div>    getAllSubUnits :: Unit subUnit -&gt; [ActiveSubUnit subUnit]</div><div>    subUnitPos     :: BoxPair -&gt; subUnit -&gt; 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&#39;t match type `Unit subUnit3&#39; with `Unit subUnit2&#39;</div>
<div>    NB: `Unit&#39; 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&#39;, namely</div><div>      `(([un], fromList $ getAllSubUnits un) ::</div><div>          SubUnit a =&gt; ([Unit a], SetActiveSubUnits a))&#39;</div><div><br></div><div>src/DeUni.hs:265:39:</div>
<div>    Couldn&#39;t match type `Unit (ActiveSubUnit subUnit3)&#39;</div><div>                   with `Unit subUnit2&#39;</div><div>    NB: `Unit&#39; 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&#39;, namely</div><div>      `(([un], fromList $ getAllSubUnits un) ::</div>
<div>          SubUnit a =&gt; ([Unit a], SetActiveSubUnits a))&#39;</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 =&gt;</div><div>                        [Point] -&gt; SetActiveSubUnits a -&gt; Box -&gt; 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 =&gt; ([Unit a1], SetActiveSubUnits a1)</div><div>      at src/DeUni.hs:265:37-117</div><div>      `a1&#39; is a rigid type variable bound by</div>
<div>           an expression type signature:</div><div>             SubUnit a1 =&gt; ([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&#39;, namely</div><div>      `(([un], fromList $ getAllSubUnits un) ::</div>
<div>          SubUnit a =&gt; ([Unit a], SetActiveSubUnits a))&#39;</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>