Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The second problem is not a whitespace problem, you have to bracket the complex patterns <code>a:as</code> and <code>b:bs</code> so you'd write <code>add res (a:as) (b:bs)</code></p> <p>To put the point about whitespace in another way, the way it looks in the <code>where</code> clause is the way it would look at the top level. You would write: </p> <pre><code>addNums1 key num = add [] key num add res (a:as) (b:bs) | as == [] = res | otherwise = add (res ++ [a+b]) as bs </code></pre> <p>So, adding indentation, you'd write</p> <pre><code> addNums2 key num = add [] key num where add res (a:as) (b:bs) | as == [] = res | otherwise = add (res ++ [a+b]) as bs </code></pre> <p>But we can't unindent your where clause so it would be on the left margin. (I modify it to something equivalent)</p> <pre><code>addNums key num = add [] key num where add res a:as b:bs | a == [] = res | otherwise = add res:(a+b) as bs </code></pre> <p>since the guards are to the left of <code>add</code>; here they actually wind up on the left margin. I recommend lining up subordinate definitions with the governing <code>where</code>:</p> <pre><code>woof xs = foldr moo baaaah xs where moo :: Integer -&gt; Integer -&gt; Integer moo x 0 = 17 moo x y = x * x + y * (y + x + 1) baaaah :: Integer baaaah = 3 -- *Main&gt; woof [1,2] -- 529 </code></pre> <p>It's not as lovely as some things, but less error prone since it decreases the cognitive load of thinking more about indentation. (And Oleg does it!) It would immediately have averted this difficulty too. I think it isn't suitable everywhere, but this is more attractive and maybe makes indentation questions clearer:</p> <pre><code> woof xs = foldr moo baaaah xs where moo :: Integer -&gt; Integer -&gt; Integer moo x 0 = 17 moo x y = x * x + y * (y + x + 1) baaaah :: Integer baaaah = 3 </code></pre> <p>Then we can see that the list of definitions in the where clause are like the list of definitions in a Haskell module, lined up with a 'left margin'.</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. 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.
 

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