<div dir="ltr"><div>Very interesting that you are mentioning looking into multi-parameter type classes! I will think a bit about it.</div><div><br></div><div>And thanks for the libraries you suggested, will also need to take some times to look into them</div><div><br></div><div>FWIW: I made an actual OOP-style code in C++ to demonstrate the difference between compile-time and run-time polymorphism</div><div><a href="https://github.com/hellwolf/haskell-examples/blob/master/2022-05-25-inclusion-polymorphism/AnyNum.cpp">https://github.com/hellwolf/haskell-examples/blob/master/2022-05-25-inclusion-polymorphism/AnyNum.cpp</a></div><div><br></div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 27, 2022 at 12:32 AM Olaf Klinke <<a href="mailto:olf@aatal-apotheke.de">olf@aatal-apotheke.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> So my central questions for discussions are:<br>
> <br>
> - Is inclusion polymorphism something we should use at all in Haskell?<br>
> - These boiler plate code maybe better be generated using Haskell template<br>
> instead, is there one already, or should<br>
>   there be one?<br>
<br>
Maybe one of the authors of a sub-typing library can share a more<br>
informed opinion on this. My view as a mathematician: <br>
A type being a subtype of another is a relation between types. <br>
Relations between types is what multi-parameter type classes is about. <br>
Hence it seems that this is how subtypes in Haskell ought to be done.<br>
For example, in the attenuation and records-sop package, the latter of<br>
which is based on genercis-sop, which depends on Template Haskell. So<br>
without having used any of the mentioned packages, I believe your<br>
second question can be answered with  "yes". <br>
Regarding the first question, we should probably ask ourselves how much<br>
type-safety we're sacrificing for the convenience we gain. The Num<br>
example you gave shows one possible danger: While a subtype relation<br>
may hold mathematically, the implementiation details may cause this<br>
relation to fail in reality. Example: All floating point numbers are<br>
rationals, aren't they? So there should be a subtype relation. But how<br>
to convert NaN, -infinity or -0 of type Double to a pair of Integers?<br>
<br>
Olaf<br>
<br>
</blockquote></div></div>