Note that there are some explanatory texts on larger screens.

plurals
  1. POOrphaned instances in Haskell
    primarykey
    data
    text
    <p>When compiling my Haskell application with the <code>-Wall</code> option, GHC complains about orphaned instances, for example:</p> <pre><code>Publisher.hs:45:9: Warning: orphan instance: instance ToSElem Result </code></pre> <p>The type class <code>ToSElem</code> is not mine, it's defined by <a href="http://www.haskell.org/haskellwiki/HStringTemplate" rel="noreferrer">HStringTemplate</a>.</p> <p>Now I know how to fix this (move the instance declaration into the module where Result is declared), and I know <a href="http://www.haskell.org/ghc/docs/6.10.3/html/users_guide/separate-compilation.html#orphan-modules" rel="noreferrer">why GHC would prefer to avoid orphaned instances</a>, but I still believe that my way is better. I don't care if the compiler is inconvenienced - rather it than me.</p> <p>The reason I want to declare my <code>ToSElem</code> instances in the Publisher module is because it is the Publisher module that depends on HStringTemplate, not the other modules. I am trying to maintain a separation of concerns and avoid having every module depend on HStringTemplate.</p> <p>I thought that one of the advantages of Haskell's type classes, when compared for example to Java's interfaces, is that they are open rather than closed and therefore the instances do not have to be declared in the same place as the data type. GHC's advice seems to be to ignore this.</p> <p>So, what I'm looking for is either some validation that my thinking is sound and that I would be justified in ignoring/suppressing this warning, or a more convincing argument against doing things my way.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload