Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Where clause indentation (Wink Saville)
   2. Re:  Where clause indentation (Rebecca Li)
   3. Re:  Where clause indentation (Brody Berg)


----------------------------------------------------------------------

Message: 1
Date: Fri, 20 Oct 2017 00:13:43 +0000
From: Wink Saville <w...@saville.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Where clause indentation
Message-ID:
        <CAKk8isqkFz_EvRKUHsytPSwEfKrD_XmuZDHG=ooa9mdjbf1...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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)
  |       ^
Failed, 0 modules loaded.
λ>


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 )
Ok, 1 module loaded.


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 )
Ok, 1 module loaded.
λ>


Can someone shed light on what I've done wrong?

-- Wink
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20171020/10332630/attachment-0001.html>

------------------------------

Message: 2
Date: Thu, 19 Oct 2017 17:33:46 -0700
From: Rebecca Li <rebecca...@kittyhawk.aero>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Where clause indentation
Message-ID:
        <cajnhu3pv2fnraih2dtgvcgzwwpq8jy8gbyxafkquezedxdc...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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 <w...@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)
>   |       ^
> Failed, 0 modules loaded.
> λ>
>
>
> 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 )
> Ok, 1 module loaded.
>
>
> 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 )
> Ok, 1 module loaded.
> λ>
>
>
> Can someone shed light on what I've done wrong?
>
> -- Wink
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>


-- 
Rebecca Li
rebecca...@kittyhawk.aero
617-899-2036
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20171019/333c14a5/attachment-0001.html>

------------------------------

Message: 3
Date: Fri, 20 Oct 2017 01:00:10 +0000
From: Brody Berg <brodyb...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Where clause indentation
Message-ID:
        <CAGAyAWOR=Kp4hDTU1u=xdbyosvnsntg7r9s1teqw2gy93sz...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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...@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 <w...@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)
>>   |       ^
>> Failed, 0 modules loaded.
>> λ>
>>
>>
>> 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 )
>> Ok, 1 module loaded.
>>
>>
>> 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 )
>> Ok, 1 module loaded.
>> λ>
>>
>>
>> Can someone shed light on what I've done wrong?
>>
>> -- Wink
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>
>
> --
> Rebecca Li
> rebecca...@kittyhawk.aero
> 617-899-2036
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20171020/5e153041/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 112, Issue 19
******************************************

Reply via email to