Wink Saville wink at saville.com
Fri Oct 20 00:13:43 UTC 2017

```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
[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
[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
[1 of 1] Compiling Main             ( chapter8_5-IntegralDivision.hs,
interpreted )