Wink Saville wink at saville.com
Sat Oct 21 00:19:04 UTC 2017

```Thanks Rebecca and Brody, I did some additional experimentation and, of
course indenting to under the "o" in "go" worked:

dividedBy :: Integral a => a -> a -> (a, a)
dividedBy num denom = go num denom 0
where go n d count
| n < d = (count, n)
| otherwise = go (n - d) d (count + 1)

But under or before the "g" doesn't:

dividedBy :: Integral a => a -> a -> (a, a)
dividedBy num denom = go num denom 0
where go n d count
| n < d = (count, n)
| otherwise = go (n - d) d (count + 1)

Oh and both the following work, at least for me on 8.2.1. Again the
critical part was the "|" past the "g" in "go", but the "body" of "where"
and "let" can be indented as little as one space, although it would be bad
form.

dividedBy :: Integral a => a -> a -> (a, a)
dividedBy num denom = go num denom 0
where
go n d count
| n < d = (count, n)
| otherwise = go (n - d) d (count + 1)

dividedBy' :: Integral a => a -> a -> (a, a)
dividedBy' num denom =
let
numerator = num
denominator = denom
go n d count
| n < d = (count, n)
| otherwise = go (n - d) d (count + 1)
in go numerator denominator 0

So this make having to indent the "|" in a function seem doubly weird to
me, but so be it :)

Oh, and on the lastest version I
the section Brody mentioned on page 40 seems to be on page 59 in the
subsection titled "Troubleshooting" underneath section 2.7 "Declaring
Variables.

There is even has an example that shows it's not always necessary to indent,
just that things need to be aligned.

On Thu, Oct 19, 2017 at 6:01 PM Brody Berg <brodyberg at gmail.com> wrote:

> I believe this is all covered starting on page 40 of the latest edition
> with examples just like Rebecca has shared.
>
> On Thu, Oct 19, 2017 at 17:35 Rebecca Li <rebecca.li at kittyhawk.aero>
> wrote:
>
>> 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".
>>
>> A version I got ghc to accept:
>>
>> dividedBy :: Integral a => a -> a -> (a, a)
>> dividedBy num denom = go num denom 0
>>   where go n d count
>>               | n < d = (count, n)
>>               | otherwise = go (n - d) d (count + 1)
>>
>> A similar example with let would be the following, where b lines up with
>> a
>> let a = blah
>>      b = blah'
>>
>> but this would not work since b is only one level indented, not matching
>> a.
>> let a = blah
>>  b = blah
>>
>> Hopefully the formatting goes through email..
>>
>>
>>
>> On Thu, Oct 19, 2017 at 5:13 PM, Wink Saville <wink at saville.com> wrote:
>>
>>> I created a file with the dividedBy example from Chapter 8.5 of "Haskell
>>> Programming from first principles" :
>>>
>>> dividedBy :: Integral a => a -> a -> (a, a)
>>> dividedBy num denom = go num denom 0
>>>   where go n d count
>>>       | n < d = (count, n)
>>>       | otherwise = go (n - d) d (count + 1)
>>>
>>>
>>> I get the following error when I load into ghci:
>>>
>>> \$ ghci chapter8_5-IntegralDivision.hs
>>> GHCi, version 8.2.1: http://www.haskell.org/ghc/  :? for help
>>> Loaded GHCi configuration from /home/wink/.ghci
>>> [1 of 1] Compiling Main             ( chapter8_5-IntegralDivision.hs,
>>> interpreted )
>>>
>>> chapter8_5-IntegralDivision.hs:4:7: error:
>>>     parse error (possibly incorrect indentation or mismatched brackets)
>>>   |
>>> 4 |       | n < d = (count, n)
>>>   |       ^
>>> λ>
>>>
>>>
>>> But if I put the "go" function on its own line:
>>>
>>> dividedBy :: Integral a => a -> a -> (a, a)
>>> dividedBy num denom = go num denom 0
>>>   where
>>>     go n d count
>>>       | n < d = (count, n)
>>>       | otherwise = go (n - d) d (count + 1)
>>>
>>>
>>> It does compile:
>>>
>>> \$ ghci chapter8_5-IntegralDivision.hs
>>> GHCi, version 8.2.1: http://www.haskell.org/ghc/  :? for help
>>> Loaded GHCi configuration from /home/wink/.ghci
>>> [1 of 1] Compiling IntegralDivision ( chapter8_5-IntegralDivision.hs,
>>> interpreted )
>>>
>>>
>>> Or I can put the "where" on the previous line:
>>>
>>> dividedBy :: Integral a => a -> a -> (a, a)
>>> dividedBy num denom = go num denom 0 where
>>>     go n d count
>>>       | n < d = (count, n)
>>>       | otherwise = go (n - d) d (count + 1)
>>>
>>>
>>> it also compiles:
>>>
>>> \$ ghci chapter8_5-IntegralDivision.hs
>>> GHCi, version 8.2.1: http://www.haskell.org/ghc/  :? for help
>>> Loaded GHCi configuration from /home/wink/.ghci
>>> [1 of 1] Compiling Main             ( chapter8_5-IntegralDivision.hs,
>>> interpreted )
>>> λ>
>>>
>>>
>>> Can someone shed light on what I've done wrong?
>>>
>>> -- Wink
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>>
>>>
>>
>>
>> --
>> Rebecca Li
>> rebecca.li at kittyhawk.aero
>> 617-899-2036 <(617)%20899-2036>
>> _______________________________________________
>> Beginners mailing list