Haskell - loop over user input

后端 未结 4 976
半阙折子戏
半阙折子戏 2021-02-13 21:40

I have a program in haskell that has to read arbitrary lines of input from the user and when the user is finished the accumulated input has to be sent to a function.

In

4条回答
  •  迷失自我
    2021-02-13 22:18

    You could do something like

    import Control.Applicative ((<$>))
    
    input <- unlines . takeWhile (/= "q") . lines <$> getContents
    

    Then input would be what the user wrote up until (but not including) the q.

提交回复
热议问题