[Haskell-cafe] GHC TV station?
Viktor Dukhovni
ietf-dane at dukhovni.org
Tue May 15 16:27:14 UTC 2018
> On May 15, 2018, at 12:13 PM, Sylvester via Haskell-Cafe <haskell-cafe at 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.
More information about the Haskell-Cafe
mailing list