Is a pen a half-closed bug in Haskell?

I get this error in GHCI:

*** Exception: <stdin>: hGetLine: illegal operation (handle is semi-closed)

After running this code:

main = do
    interact $ unlines . fmap proccess . take x . lines
    readLn :: IO Int

And I'm sure the reason take x. Is there a better way to read only x lines using interaction, or is it interactjust a solo player?

+4
source share
2 answers

, , interact. interact stdin hGetContents. "" , - , , ().

import Control.Monad (replicateM)

getLines :: Int -> IO [String]
getLines n = replicateM n getLine
+8

interact . readLn .

, - :

import Control.Monad

main = do input <- replicateM 10 getLine
          ...

input () 10 .

, , .

+2

Source: https://habr.com/ru/post/1650226/


All Articles