Haskell printing strings stdout

后端 未结 1 1228
鱼传尺愫
鱼传尺愫 2021-01-16 13:16

I need to print the elements in a powerset. Right now my code\'s output is this:

\"a\"
\"ab\"
\"b\"
\"x\"
\"xy\"
\"xyz\"
\"xz\"
\"y\"
\"yz\"
\"z\"

相关标签:
1条回答
  • 2021-01-16 13:36

    First (\x -> f x) is equivalent to plain f (in almost all cases) by eta-reduction. So, you can re-write mapM (\x -> print x) as mapM print.

    To remove the quotation marks, you should use the function putStrLn instead of the print function. The quotation marks in print come from print = putStrLn . show. show is a function that prints out values in a way that can (if a suitable instance is defined) be read back in with read. Thus, quotation marks on strings, which you don't want (or need) for your use-case.

    0 讨论(0)
提交回复
热议问题