It looks like you may be trying to do this with a proportional font, which is not going to work very well. You will have much better luck if you use a fixed width font when you need to line up columns where some of the lines have non-whitespace characters.

An alternative approach would be to have a line break immediately after "do", so all of the lines that need to be indented have only preceding whitespace. The hindent code formatter uses this style, as you can see in any of its examples with do blocks, such as this: https://github.com/commercialhaskell/hindent/blob/master/TESTS.md#function-declarations - when code is written in this style, the blocks will line up visually whether or not the font is fixed width.



On Tue, May 15, 2018 at 10:02 AM Sylvester Hazel via Haskell-Cafe <haskell-cafe@haskell.org> wrote:
Hi Victor,
It is frustrating that posting plain text is contorted (via nabble.com and then again in my mail.google.com account) - please see the attachment.
I really have sent the right indentation copping the Hutton's script.
Is it so difficult for you guys to replicate this obvious failure of GHC on "do notation" with white space?
Regards,
Sylvester

On Tue, May 15, 2018 at 6:27 PM, Viktor Dukhovni <ietf-dane@dukhovni.org> wrote:


> On May 15, 2018, at 12:13 PM, Sylvester via Haskell-Cafe <haskell-cafe@haskell.org> wrote:
>
> strlen in Hutton 2ed 10.5 Derived primitives => run on Windows 7 Haskell
> Platform 8.2.2
> strlen :: IO ()
> strlen = do  putStr "Enter a string: "
>                   xs <-  getLine
>                   putStr "The string has "
>                   putStr (show (length xs))
>                   putStr " characters"
> ===================================================

The above indentation looks wrong.  Try:

----------
$ cat foo.hs
strlen :: IO ()
strlen = do putStr "Enter a string: "
            xs <-  getLine
            putStr "The string has "
            putStr (show (length xs))
            putStrLn " characters"

$ ghci foo.hs
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( foo.hs, interpreted )
Ok, modules loaded: Main.
Loaded GHCi configuration from /tmp/haskell-stack-ghci/05485125/ghci-script
*Main> strlen
Enter a string: foo
The string has 3 characters
*Main>
----------

If I incorrectly indent the subsequent lines:

strlen :: IO ()
strlen = do putStr "Enter a string: "
              xs <-  getLine
              putStr "The string has "
              putStr (show (length xs))
              putStrLn " characters"


Then I see an error:

foo.hs:2:13: error:
    Parse error in pattern: putStr
    Possibly caused by a missing 'do'?

--
        Viktor.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.