<div dir="ltr">Taking inspiration from <a href="http://stackoverflow.com/questions/24775080/how-to-establish-an-ordering-between-types-in-haskell">http://stackoverflow.com/questions/24775080/how-to-establish-an-ordering-between-types-in-haskell</a>, this comes out to be the solution:<div>---</div><div><div style="font-size:13px">type family Super (a :: *) :: *</div><div style="font-size:13px"><br></div><div style="font-size:13px">class Extends a b where</div><div style="font-size:13px"> supercast :: a -> b</div><div style="font-size:13px"><br></div><div style="font-size:13px">instances Extends a a</div><div style="font-size:13px">instance {-# INCOHERENT #-} (Super a ~ b, Extends b c) => Extends a c</div></div><div style="font-size:13px">---</div><div style="font-size:13px">But this solution does rely on UndecidableInstances, but since it works it's fine.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 5, 2016 at 10:01 AM, Rahul Muttineni <span dir="ltr"><<a href="mailto:rahulmutt@gmail.com" target="_blank">rahulmutt@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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="m_-9046384712292511133gmail_signature">Rahul Muttineni</div>
</div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Rahul Muttineni</div>
</div>