我如何在Haskell中使用getLine或getChar? [英] How can I use getLine or getChar in haskell?
本文介绍了我如何在Haskell中使用getLine或getChar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从我的控制台获取一个字符串
或只是一个 char
并存储到一个变量中。
我尝试过使用:
>让x = getChar
> x
> c - 获取字符。
但是没有任何东西被存储(getLine也一样)我该怎么办?
解决方案
从控制台读取,可能不是很有用。但是,您应该使用< -
构造。 例如(不包含
> myString< - getLine
>Hello world
或
> myChar< - getChar
> c
我建议阅读此处
I'm trying to get from my console a string
or just a char
and store into a variable.
I tried to use:
> let x = getChar
> x
> c -- for getting a char.
But nothing is stored (same for getLine) how can I do?
解决方案
Reading from console, maybe is not very useful. However you should use <-
construct.
For example (without "
is good too) :
>myString <- getLine
>"Hello world"
or
>myChar <- getChar
>c
For more I suggest to read here
这篇关于我如何在Haskell中使用getLine或getChar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文