io - Haskell interact() truncating my output? -
i'm working on basic haskell program contains line of code:
interact (unwords . (map piglatin . words) )
however, after passing array of strings piglatin function, wrapping string, truncates last word enter. instance:
*haskellpractice> getuserinput broken histay isway
for reason not printing that. on mac, have following options declared in getuserinput before call interact:
hsetbuffering stdin linebuffering hsetbuffering stdout nobuffering
i'm guessing it's small detail have yet understand. input/help! osftw edit: here's whole program.
import system.io piglatin :: string -> string piglatin word = if ( (head word) `elem`['a', 'e', 'i', 'o', 'u'] ) (word ++ "way") else (tail word) ++ [(head word)] ++ "ay" getuserinput = hsetbuffering stdin linebuffering hsetbuffering stdout nobuffering interact (unwords . (map piglatin . words) )
here program tested:
import system.io piglatin xs = "[" ++ xs ++ "]" main = hsetbuffering stdin linebuffering hsetbuffering stdout nobuffering interact (unwords . (map piglatin . words) )
and here ghci
session looks like:
*main> :main line1 [this] [is] line2 [line1] [this] [is] [line2]<stdin>: hgetbuffering: illegal operation (handle closed)
i typed:
this line1 line2 (control-d)
so it's not truncating input - it's not emitting last word in line until next line read (or eof encountered.)
if run shell expect:
shell$ (echo line1; echo line2) | runhaskell ./platin.hs [this] [is] [line1] [this] [is] [line2]
Comments
Post a Comment