Haskell:解析输入错误'putStrLn' [英] Haskell: parse error on input 'putStrLn'

查看:268
本文介绍了Haskell:解析输入错误'putStrLn'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚写了我的第一个Haskell程序,但是有一个我无法理解的错误。我认为这是对的,因为我只是像书中的例子那样写它。任何人都可以帮助我吗?

I just wrote my first Haskell program, but there is an error that I cannot understand. I think it is right because I just wrote it like the example from a book. Could anyone help me please?

main = do
    putStrLn "Hello, what's your name?"
    name <- getLine
    putStrLn ("Hey" ++ name ++ ", nice to meet you!")

错误消息是:

The error message is:


输入'putStrLn'解析错误

parse error on input 'putStrLn'

很奇怪。

It is strange.

推荐答案

从你发布的代码中知道,因为SO至少在某些时候将标签转换为空格,问题可能是你在 putStrLn 之前输入了一个文字标签字符,而不是四个空格您为 do 块中的其他两行执行了操作,反之亦然。

Though it's impossible to tell from your posted code because SO converts tabs to spaces at least some of the time, the problem is likely that you input a literal tab character before putStrLn instead of four spaces as you did for the other two lines in your do block, or vice versa.

所有语句 do 块必须以完全相同的空格开始,而不是直观地排列起来。如果您使用的是可以以特殊方式显示文字标签的文本编辑器,请将其设置为这样;它会为您节省一些麻烦。

All of the statements in a do block must start with the exact same whitespace, and not just appear to line up visually. If you're using a text editor that can display literal tabs in a special way, set it up to do so; it will save you some headaches.

这篇关于Haskell:解析输入错误'putStrLn'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆