Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, in general, the code:</p> <pre><code>a `f` b </code></pre> <p>is just syntactic sugar for:</p> <pre><code>f a b </code></pre> <p>Therefore your code became:</p> <pre><code>mempty PQ.singleton [start] </code></pre> <p>So the type-checker inferred the type for that particular mempty:</p> <pre><code>mempty :: (k -&gt; a -&gt; PQ.MinPQueue k a) -&gt; [Node] -&gt; PQ.MinPQueue b [Node] </code></pre> <p>You correctly found the right instance that is the problem. Anything of type <code>a -&gt; b</code> is a <code>Monoid</code>, provided that <code>b</code> is. So let's bracket that type above:</p> <pre><code>mempty :: (k -&gt; a -&gt; PQ.MinPQueue k a) -&gt; ([Node] -&gt; PQ.MinPQueue b [Node]) </code></pre> <p>So, that type can be a <code>Monoid</code> if <code>[Node] -&gt; PQ.MinPQueue b [Node]</code> is a <code>Monoid</code>. And by the same logic, <code>[Node] -&gt; PQ.MinPQueue b [Node]</code> can be a <code>Monoid</code> if <code>PQ.MinPQueue b [Node]</code> is one. Which it is. So the type-checker is fine with this code.</p> <p>Presumably the implementation of our troublesome instance is:</p> <pre><code>instance Monoid =&gt; Monoid (a -&gt; b) where mempty = const mempty </code></pre> <p>So overall, you get an empty priority queue. So really, I think it comes down to a question of whether it was wise for the designers to include this instance at all. Its net effect is that any function returning a monoid can be a monoid, which should allow you to combine the results. The more useful case here is mappend, which can append two <code>a -&gt; b</code> functions by applying them both and using <code>mappend</code> to combine the results. For example:</p> <pre><code>extremes = (return . minimum) `mappend` (return . maximum) </code></pre> <p>rather than:</p> <pre><code>extremes xs = [minimum xs, maximum xs] </code></pre> <p>Hmmm, maybe someone else can produce a sensible terser example.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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