Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It appears you have two issues with your <code>insert</code> function.</p> <p>First, your two definitions of the <code>insert</code> function return different things.</p> <pre><code>Set [list] -- Return type here is Collection </code></pre> <p>and</p> <pre><code>[list] ++ numberToInsert -- Return type here is some sort of list, or [a0] </code></pre> <p>So first, you'll need to Make the second version return a <code>Collection</code>:</p> <pre><code>Set ([list] ++ numberToInsert) </code></pre> <p>But this is still wrong, because <code>numberToInsert</code> is not a list, and <code>++</code> concatenates two lists together, so I think you're really wanting to push it onto the front of your <code>[list]</code>. <code>:</code> is used to push some <code>a</code> onto the front of a list of <code>as</code> Like so:</p> <pre><code>Set (numberToInsert:[list]) </code></pre> <p>Finished product:</p> <pre><code>insert :: Int -&gt; Collection -&gt; Collection insert numberToInsert (Set [list]) | contains (Set [list]) numberToInsert == True = (Set [list]) | otherwise = Set (numberToInsert : [list]) </code></pre> <p><strong>Update</strong></p> <p>As you mentioned, there is one other issue I'd missed. <code>list</code> shouldn't be wrapped in the square brackets, and here's why (in case you hadn't figured it out).</p> <p>When you use the square brackets in a pattern match (the left side of the <code>=</code>), you're saying: "give me a list that looks like this, and bind it's only item to some name for use later". So you were only expecting a list with one item, and decided to call that item <code>list</code>.</p> <p>Next, you repackaged up that one item in the new list when you used it as <code>[list]</code>.</p> <p>this example:</p> <pre><code>foo [a] = a main = print $ foo [1] </code></pre> <p>would print '1'. Passing a list of two items, however, would fail to pattern match, because you had no <code>foo [a, b] = ...</code> function defined, hence the warning:</p> <pre><code>main = print $ foo [1, 2] </code></pre> <p>So yes, removing all of the square brackets works because you are not requiring the list have only one item, but instead saying "the entire list will be called <code>list</code>", which is probably what you wanted in the first place.</p>
    singulars
    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