Haskell: initial syntax question

a very simple question from a student of Haskell. I work through Another Haskell Tutorial , and I follow a simple syntactical practice. The code below: When I copy and paste it (from pdf) and then indent it, it works fine, but when I enter it into the editor (in my case Notepad ++), it gives the following error:

Guess.hs:8:9: parse error on input ยดhSetBufferingยด 

I made sure that I did not mix tabs and spaces (4 spaces), and I did not find typos in the book. I am sure this is a very simple mistake, so thanks for any input.

Nebelhom

Here is the code:

 module Main where import IO import Random main = do hSetBuffering stdin LineBuffering num <- randomRIO (1::Int, 100) putStrLn "I'm thinking of a number between 1 and 100" doGuessing num doGuessing num = do putStrLn "Enter your guess:" guess <- getLine let guessNum = read guess if guessNum < num then do putStrLn "Too low!" doGuessing num else if read guess > num then do putStrLn "Too high!" doGuessing num else do putStrLn "You Win!" 
+4
source share
1 answer

There is no syntax error that I can see or reproduce:

 $ ghci A.hs GHCi, version 7.0.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading package ffi-1.0 ... linking ... done. [1 of 1] Compiling Main ( A.hs, interpreted ) Ok, modules loaded: Main. 

which means these are probably tabs. Have you pasted a tab somewhere? And then use 4 spaces for indentation? In general, there are tabs in Haskell because they lead to unintended and incomprehensible syntax errors.

+3
source

All Articles