Haskell compiler error: not in scope

I am trying to learn haskell by writing a simple copy of a file:

main = do
         putStr "Source: "
         srcPath <- getLine
         putStr "Destination: "
         destPath <- getLine
         putStrLn ("Copying from " ++ srcPath ++ " to " ++ destPath ++ "...")
         contents <- readFile srcPath
         writeFile destPath contents
         putStrLn "Finished"

It gets me

GHCi, version 6.10.4: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done. 
[1 of 1] Compiling Main             ( D:\Test.hs, interpreted )

D:\Test.hs:8:22: Not in scope: `contents' 
Failed, modules loaded: none.
Prelude>

I do not understand what a compiler error is because the variable looks normal. What's wrong?

Here's the repeater: on rapidshare

+3
source share
2 answers

It looks like you have mixed tabs and spaces (just look at your question in the "edit" view to see the problem). Although your editor views the code with uniform indentation, the compiler seems to have a different interpretation of how the wide tab should be, with the result that the line writeFile destPath contentswill have extra indentation. Therefore, the source is interpreted as follows:

  ...
  putStrLn ("Copying from " ++ srcPath ++ " to " ++ destPath ++ "...")
  contents <- readFile srcPath writeFile destPath contents
  putStrLn "Finished"

contents , .

, , , , .

+13

. .hs GHCi. , GHC, .

+1

Source: https://habr.com/ru/post/1722217/


All Articles