Haskell做语法和I / O.(Haskell do syntax and I/O)

我正在玩Haskell中的一个简单程序:

hello :: String -> String
hello s = "Hello, " ++ (trim s) ++ "!\n"

trim :: String -> String
trim [] = []
trim s = head $ words s

main :: IO()
main = do putStr "\nPlease enter your name: "
          name <- getLine
          hstring <- return $ hello name
          putStr hstring

这是我期待的输出:

Please enter your name: John Doe
Hello, John!

当我将程序加载到ghci时,这可以正常工作。 但是当我使用编译程序时

ghc -o hello.exe hello.hs

它启动,等待输入,然后同时打印两个提示:

John Doe
Please enter your name: Hello, John!

为什么交互式环境和编译器之间的行为有所不同,我如何让编译器做我想做的事情?

先谢谢您的帮助!


I was playing around with a simple program in Haskell:

hello :: String -> String
hello s = "Hello, " ++ (trim s) ++ "!\n"

trim :: String -> String
trim [] = []
trim s = head $ words s

main :: IO()
main = do putStr "\nPlease enter your name: "
          name <- getLine
          hstring <- return $ hello name
          putStr hstring

This is the output I am expecting:

Please enter your name: John Doe
Hello, John!

This works as expected when I load the program into ghci. However when I compile the program using

ghc -o hello.exe hello.hs

it starts, waits for input, and then prints both prompts at the same time:

John Doe
Please enter your name: Hello, John!

Why is the behavior different between the interactive environment and compiler, and how can I make the compiler do what I want?

Thanks in advance for the help!


原文:https://stackoverflow.com/questions/6222521
2024-02-10 14:02

满意答案

您应该添加该属性

android:windowSoftInputMode="stateAlwaysHidden"

给你在AndroidManifest.xml中的活动


You should add the attribute

android:windowSoftInputMode="stateAlwaysHidden"

to you activity in AndroidManifest.xml

相关问答

更多

活动开始时,屏幕键盘会自动打开(OnScreen keyboard opens automatically when Activity starts)

如果您在活动启动时有一个EditText焦点,Android会自动打开OnScreenKeyboard。 您可以通过将以下内容添加到您的Activity的onCreate方法中来防止这种情况。 getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); Android opens the OnScreenKeyboard automatically if you ha...

带有EditText的AlertDialog,自动打开软键盘,重点放在EditText上不起作用(AlertDialog with EditText, open soft keyboard automatically with focus on EditText doesn't work)

好吧,我设法让它工作: Builder builder = new Builder(this); final EditText input = new EditText(this); builder .setTitle(R.string.dialog_title_addsubject) .setMessage(R.string.dialog_addsubject) ...

自动显示键盘(Show keyboard automatically)

我认为这是一个错误或功能,它试图向您展示整个活动,而不是先用软键盘遮掩它。 我曾经搜索过一次有关这方面的信息,但不幸的是没有发现任何来自真正可靠的来源。 无论如何,要显示软键盘,你可以这样做: EditText editText = (EditText)findViewById(R.id.edit_text_id); InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)...

如何在UITextField上自动打开键盘?(How to open the keyboard automatically on UITextField?)

要使键盘立即显示,您需要使用以下行将文本字段设置为第一个响应者: [textField becomeFirstResponder]; 您可能希望将其放在viewDidAppear:方法中。 To cause the keyboard to show up immediately you'll need to set the text field as the first responder using the following line: [textField becomeFirstRespo...

Android:当焦点在EditText上时自动显示软键盘(Android: show soft keyboard automatically when focus is on an EditText)

您可以在AlertDialog上的EditText上创建焦点侦听AlertDialog ,然后获取AlertDialog的Window 。 从那里,您可以通过调用setSoftInputMode使软键盘显示。 final AlertDialog dialog = ...; editText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(...

当Activity启动时,EditText具有焦点,但不显示软键盘(EditText has focus when Activity starts, but soft keyboard is not shown)

尝试这样的事情: EditText myEditText = (EditText) findViewById(R.id.editPasswd); ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)) .showSoftInput(myEditText, InputMethodManager.SHOW_FORCED); 你在模拟器上测试吗? 如果你这样做,你应该知道键盘不会在模拟器上弹出:),但它确实在...

EditText焦点自动打开键盘(EditText focus opens Keyboard automatically)

您应该添加该属性 android:windowSoftInputMode="stateAlwaysHidden" 给你在AndroidManifest.xml中的活动 You should add the attribute android:windowSoftInputMode="stateAlwaysHidden" to you activity in AndroidManifest.xml

如何在EditText获得焦点时自动显示软键盘(How Show soft keyboard automatically when EditText receives focus)

您还可以为活动添加标记,这将自动显示键盘 <activity name="package.ActivityName" android:windowSoftInputMode="stateVisible"/> 如果您希望在活动启动时应用焦点,这将非常有用 你也可以在片段中使用: InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm....

如何让Edittext的软键盘输出得到焦点(How to let the soft keyboard output from the Edittext which gets focus)

删除android:focusable属性,android:foucsableInTouchMode属性和XML文件中的标签,立即行动,然后 public class YOURMAINActivity extends Activity implements OnClickListener { private EditText editTxt1; private EditText editTxt2; @Override public void onCreate(Bundl...

wpf键盘焦点:菜单打开后失去焦点?(wpf keyboard focus: losing focus after menu opens?)

我仍然不确定为什么会这样,但这是我找到的解决方案: 在窗口上设置Focusable="False"和FocusManager.IsFocusScope="False" 。 在控件上设置Focusable="True"和FocusManager.IsFocusScope="True" 。 三。 使用以下内容: PleasedPanda.LostKeyboardFocus += (sender, e) => { if(e.NewFocus == null) { Keyb...

相关文章

更多

Hadoop的I/O

1. 数据完整性:任何语言对IO的操作都要保持其数据的完整性。Hadoop当然希望数据在存储和处理中不 ...

Hadoop I/O系统介绍

看过很多Hadoop介绍或者是学习的帖子和文章,发现介绍Hadoop I/O系统的很少。很多文章都会介 ...

Hadoop1.0.4 HDFS I/O性能测试

分布式RDF查询引擎的项目需要在节点之间传输中间结果,考虑HDFS可以作为一个备选的传输媒介,于是对H ...

Java中如何用I/O流读取一个Word文档的内容?

BufferedReader br = new BufferedReader(new FileRead ...

O2O

啥是O2O?一句两句话解释不清楚,行业也没有统一的定义,O2O的英文全拼是Online To Offl ...

WiFi入口流量O2O微应用平台

WiFi入口流量O2O微应用平台 随着智能手机一年比一年销量大好,传统的互联网的流量争夺战场已经转向 ...

阿虎烧烤的新感悟-O2O你真的会玩吗?

文章转自码客园-关注码农创业,着力打造IT技术分享和信息传播平台。更多O2O内容尽在码客园 因为尝试了 ...

玩电商?O2O才是微信想要的

昨天微信小店登场,又有很多大师、微信达人、各路哥开始鼓吹微信小店的惊世骇俗。其实微信卖东西由来已久,并 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本