0

I have a main function that outputs unicode which looks like this:

main = do
    hSetEncoding stdout utf8
    input <- getContents
    mapM_ putStr $ myfunc input

How can I write this function without do notation?

I get <stdout>: commitBuffer: invalid argument (invalid character) when I try to compile this main function:

main = getContents >>= mapM_ putStr . myfunc

1 Answer 1

3

Just use sequence (>>):

main = do
    hSetEncoding stdout utf8
    input <- getContents
    mapM_ putStr $ myfunc input

~~>

main = hSetEncoding stdout utf8 >> getContents >>= \input -> mapM_ putStr $ lines input

~~>

main = hSetEncoding stdout utf8 >> getContents >>= mapM_ putStr . lines
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.