Prelude> mapM putStrLn ["a", "b"]
a
b
[(),()]
Prelude> mapM_ putStrLn ["a", "b"]
a
b
Why first version shows third line and second does not and where does third line comes from. I would not expect it.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you put the
mapMversion in a standalone program, compile it withghc, and run it, you don’t get a third line from it, either:That
[(),()]you see inghciis just the return value of themapMcall;ghciautomatically displays the value of every expression you enter. (This is whyghciis called a Read-Evaluate-Print Loop, or REPL; the “Print” part is what you’re seeing here.)While
mapMcreates a list containing the return value of everyputStrLncall (so you get one()for each element in the list),mapM_discards those return values and returnsIO (), whichghcidoesn’t bother to display. So you don’t see an extra line fromghciin that case.