English 中文(简体)
为什么这部法典有 par错?
原标题:Why Haskell is giving a parse error for this code?
  • 时间:2012-01-16 05:51:27
  •  标签:
  • haskell

我正试图制定一个方案,读到用户提供的数字,然后印制。 在我印刷时,数字必须呈立体字,但该代码给我留下一个大错:

main = do
{
       putStrLn "Please enter the number"
       number <- getLine
       putStrLn "The num is:" ++ show (read number:: Int)
}
问题回答

If you use brackets in your do statement, you have to use semicolons. Also, the last line should be putStrLn $ "The num is:" ++ show (read number :: Int)

因此,你有两个选择:

main = do
{
   putStrLn "Please enter the number";
   number <- getLine;
   putStrLn $ "The num is:" ++ show (read number:: Int)
}

or:

main = do
   putStrLn "Please enter the number"
   number <- getLine
   putStrLn $ "The num is:" ++ show (read number:: Int)

我所看到的几乎所有法典都使用了第二版,但它们都有效。 请注意,在第二版中,白天空间变得巨大。

Haskell recognizes the Tab character and your program could be failing because of that. If you re using Tabs, change them to whitespaces.





相关问题
Euler Problem in Haskell -- Can Someone Spot My Error

I m trying my hand at Euler Problem 4 in Haskell. It asks for that largest palindrome formed by multiplying two three-digit numbers. The problem was simple enough, and I thought my Haskell-fu was up ...

How does foldr work?

Can anybody explain how does foldr work? Take these examples: Prelude> foldr (-) 54 [10, 11] 53 Prelude> foldr (x y -> (x+y)/2) 54 [12, 4, 10, 6] 12.0 I am confused about these executions....

Efficient queue in Haskell

How can I efficiently implement a list data structure where I can have 2 views to the head and end of the list, that always point to a head a tail of a list without expensive calls to reverse. i.e: ...

Problem detecting cyclic numbers in Haskell

I am doing problem 61 at project Euler and came up with the following code (to test the case they give): p3 n = n*(n+1) `div` 2 p4 n = n*n p5 n = n*(3*n -1) `div` 2 p6 n = n*(2*n -1) p7 n = n*(5*n -3)...

Ways to get the middle of a list in Haskell?

I ve just started learning about Functional Programming, using Haskel. I m slowly getting through Erik Meijer s lectures on Channel 9 (I ve watched the first 4 so far) and in the 4th video Erik ...

haskell grouping problem

group :: Ord a => [(a, [b])] -> [(a, [b])] I want to look up all pairs that have the same fst, and merge them, by appending all the list of bs together where they have the same a and discarding ...

Closest equivalent to subprocess.communicate in Haskell

I want to do a popen() / python s subprocess.communicate from Haskell - start a program, give it stdin, and get its stdout/stderr. What s the most direct / Haskellish way to do this?

热门标签