Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, here is a working version:</p> <pre><code>module Network where data Loc = Loc deriving (Show, Eq) data Pair = Conn Loc Loc | Disconn Loc Loc deriving(Show,Eq) data NC = EmpNC | Inn Pair NC instance Eq NC where EmpNC == EmpNC = True (Inn p nc1) == nc2 = (nc_include p nc2) &amp;&amp; (nc1 == nc2) _ == _ = False nc_include :: Pair -&gt; NC-&gt; Bool nc_include p EmpNC = False nc_include p1 (Inn p2 nc) = (p1 == p2) || (nc_include p1 nc) </code></pre> <p>What's the difference (besides my arbitrarily defining <code>Loc</code>)? Mainly formatting. </p> <p>I suppose what happened is this:</p> <p>You tried to write an instance of <code>Eq</code> for <code>NC</code>:</p> <pre><code>instance Eq NC where EmpNC == EmpNC = True ... </code></pre> <p>and realized the compiler didn't like this, saying it conflicted with <code>(==)</code> from the <code>Prelude</code>. However, you drew the wrong conclusions from this, hiding <code>Prelude.(==)</code> and going on. Now the compiler didn't complain, but it parsed what you did like this:</p> <pre><code>instance Eq NC where -- make NC an instance of Eq with only default definitions EmpNC == EmpNC = True -- define a new function (==) of type (NC -&gt; NC -&gt; Bool) ... </code></pre> <p>That's why now you can't apply <code>(==)</code> to <code>Pair</code>s, because it's type is <code>(NC -&gt; NC -&gt; Bool)</code>, hence the compiler tells you that it would have expected an <code>NC</code> instead of a <code>Pair</code>.</p> <p>Now, the core of the matter is that instance definitions follow whitespace formatting rules, so you must leave at least one whitespace column before the functions in your <code>instance</code> definition:</p> <pre><code>instance Eq NC where EmpNC == ... </code></pre> <p>works, while </p> <pre><code>instance Eq NC where EmpNC == ... </code></pre> <p>doesn't.</p> <p>The same is true for some other things like <code>class</code>, <code>do</code>, <code>case</code> etc.</p>
 

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