<div dir="ltr"><div>Hi cafe,</div><div><br></div>I want to embed Java class hierarchies in Haskell, but I am unable to find a clean way to do it.<div><br></div><div>Assume the class hierarchy C derives from B derives from A.</div><div><br></div><div>Partial Solution:</div><div>---</div><div><div>type family Super (a :: *) :: *</div><div><br></div><div>class Extends a b where</div><div>  supercast :: a -> b</div><div><br></div><div>instance {-# INCOHERENT #-} (Class a, Class c, Super a ~ b, Super b ~ c) => Extends a c where<br></div></div><div><br></div><div>data A</div><div>data B</div><div>data C</div><div><br></div><div>type instance Super C = B</div><div>type instance Super B = A</div><div>instance Extends C B</div><div>instance Extends B A</div><div>--</div><div><div><br></div><div>This is fine and is successfully able to infer Extends C A, but it's redundant and cannot infer that Extends D A if we let Super D = C. Is there a way to only specify the parent-child relationship once and get GHC to infer the entire hierarchy without the use of UndecidableInstances?  Other solutions I've tried which avoid redundancy cause an infinite loop in the context reduction step of GHC.</div><div><br></div>Thanks,<br><div class="gmail_signature">Rahul Muttineni</div>
</div></div>