Haskell interact()是否截断我的输出?

Haskell interact()是否截断我的输出?,haskell,io,functional-programming,Haskell,Io,Functional Programming,我正在编写一个基本的Haskell程序,其中包含以下代码行: interact (unwords . (map pigLatin . words) ) 但是,在将字符串数组传递给我的pigLatin函数,然后再包装回字符串之后,它总是截断我输入的最后一个单词。例如: *HaskellPractice> getUserInput this is broken histay isway 出于某种原因,它并没有打印那个。 我在Mac上,因此在调用Interactive之前,我在getUse

我正在编写一个基本的Haskell程序,其中包含以下代码行:

interact (unwords . (map pigLatin . words) )
但是,在将字符串数组传递给我的pigLatin函数,然后再包装回字符串之后,它总是截断我输入的最后一个单词。例如:

*HaskellPractice> getUserInput
this is broken
histay isway 
出于某种原因,它并没有打印那个。 我在Mac上,因此在调用Interactive之前,我在getUserInput中声明了以下选项:

hSetBuffering stdin LineBuffering
hSetBuffering stdout NoBuffering
我猜这是一个我还没有完全理解的小细节。感谢您的任何意见/帮助! OSFTW 编辑:这是整个程序

    import System.IO

pigLatin :: String -> String
pigLatin word = if ( (head word) `elem`['a', 'e', 'i', 'o', 'u'] )
    then (word ++ "way")
        else  (tail word) ++ [(head word)] ++ "ay"

getUserInput = do
    hSetBuffering stdin LineBuffering
    hSetBuffering stdout NoBuffering

    interact (unwords . (map pigLatin . words) )

以下是我测试的程序:

import System.IO

pigLatin xs = "[" ++ xs ++ "]"

main = do
  hSetBuffering stdin LineBuffering
  hSetBuffering stdout NoBuffering
  interact (unwords . (map pigLatin . words) )
下面是一个
ghci
会话的样子:

*Main> :main
this is line1
[this] [is] this is line2
[line1] [this] [is] [line2]<stdin>: hGetBuffering: illegal operation (handle is closed)
因此,它不会截断输入—它只是在读取下一行(或遇到EOF)之前不会发出行中的最后一个字

如果您从shell运行它,您将得到您所期望的:

shell$ (echo this is line1; echo this is line2) | runhaskell  ./platin.hs

[this] [is] [line1] [this] [is] [line2]

你能发布一个完整的程序来复制这个问题吗?当您从ghci运行Control-d时,是否在输入的末尾键入了Control-d?感谢您的关注!我更新了操作。是的,我正在按control-d
shell$ (echo this is line1; echo this is line2) | runhaskell  ./platin.hs

[this] [is] [line1] [this] [is] [line2]