<div dir="ltr">I believe for where (as well as with let, or any other special phrasing), if you're putting something on the same line with it, the subsequent lines have to begin after the end of the indentation of the word "where" or "let". <div><br></div><div>A version I got ghc to accept:</div><div><div><br></div><div>dividedBy :: Integral a => a -> a -> (a, a)</div><div>dividedBy num denom = go num denom 0</div><div>  where go n d count</div><div>              | n < d = (count, n)</div><div>              | otherwise = go (n - d) d (count + 1)</div></div><div><br></div><div>A similar example with let would be the following, where b lines up with a </div><div>let a = blah</div><div>     b = blah'</div><div><br></div><div>but this would not work since b is only one level indented, not matching a. </div><div>let a = blah</div><div> b = blah</div><div><br></div><div>Hopefully the formatting goes through email.. </div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 19, 2017 at 5:13 PM, Wink Saville <span dir="ltr"><<a href="mailto:wink@saville.com" target="_blank">wink@saville.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I created a file with the dividedBy example from Chapter 8.5 of "Haskell Programming from first principles" :<div><div><br></div></div><div><div>dividedBy :: Integral a => a -> a -> (a, a)</div><div>dividedBy num denom = go num denom 0</div><div>  where go n d count</div><div>      | n < d = (count, n)</div><div>      | otherwise = go (n - d) d (count + 1)</div><div><br></div></div><div><br></div><div>I get the following error when I load into ghci:</div><div><br></div><div><div><div><div>$ ghci chapter8_5-IntegralDivision.<wbr>hs </div><div>GHCi, version 8.2.1: <a href="http://www.haskell.org/ghc/" target="_blank">http://www.haskell.org/ghc/</a>  :? for help</div><div>Loaded GHCi configuration from /home/wink/.ghci</div><div>[1 of 1] Compiling Main             ( chapter8_5-IntegralDivision.<wbr>hs, interpreted )</div><div><br></div><div>chapter8_5-IntegralDivision.<wbr>hs:4:7: error:</div><div>    parse error (possibly incorrect indentation or mismatched brackets)</div><div>  |</div><div>4 |       | n < d = (count, n)</div><div>  |       ^</div><div>Failed, 0 modules loaded.</div><div>λ> </div></div></div></div><div><br></div><div><br></div><div>But if I put the "go" function on its own line:</div><div><br></div><div><div>dividedBy :: Integral a => a -> a -> (a, a)<br></div><div>dividedBy num denom = go num denom 0</div><div>  where</div><div>    go n d count</div><div>      | n < d = (count, n)</div><div>      | otherwise = go (n - d) d (count + 1)</div></div><div><br></div><div><br></div><div>It does compile:</div><div><br></div><div><div>$ ghci chapter8_5-IntegralDivision.<wbr>hs </div><div>GHCi, version 8.2.1: <a href="http://www.haskell.org/ghc/" target="_blank">http://www.haskell.org/ghc/</a>  :? for help</div><div>Loaded GHCi configuration from /home/wink/.ghci</div><div>[1 of 1] Compiling IntegralDivision ( chapter8_5-IntegralDivision.<wbr>hs, interpreted )</div><div>Ok, 1 module loaded.</div></div><div><br></div><div><br></div><div>Or I can put the "where" on the previous line:</div><div><br></div><div><div><div>dividedBy :: Integral a => a -> a -> (a, a)</div><div>dividedBy num denom = go num denom 0 where</div><div>    go n d count</div><div>      | n < d = (count, n)</div><div>      | otherwise = go (n - d) d (count + 1)</div></div></div><div><br></div><div><br></div><div>it also compiles:</div><div><br></div><div><div>$ ghci chapter8_5-IntegralDivision.<wbr>hs </div><div>GHCi, version 8.2.1: <a href="http://www.haskell.org/ghc/" target="_blank">http://www.haskell.org/ghc/</a>  :? for help</div><div>Loaded GHCi configuration from /home/wink/.ghci</div><div>[1 of 1] Compiling Main             ( chapter8_5-IntegralDivision.<wbr>hs, interpreted )</div><div>Ok, 1 module loaded.</div><div>λ> </div></div><div><br></div><div><br></div><div>Can someone shed light on what I've done wrong?</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-- Wink</div></font></span></div>
<br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Rebecca Li<br></div><a href="mailto:rebecca.li@kittyhawk.aero" target="_blank">rebecca.li@kittyhawk.aero</a><br>617-899-2036<br></div></div>
</div>