string 如何在haskell中打印列表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5952167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 01:06:13  来源:igfitidea点击:

how do I print a list in haskell?

stringhaskellio

提问by Alexander Bird

How do I print a list to stdout in Haskell?

如何在 Haskell 中将列表打印到标准输出?

Let's say I have a list [1,2,3]and I want to convert that list into a string and print it out. I guess I could build my own function, but surely Haskell has a function built in to do that.

假设我有一个列表[1,2,3],我想将该列表转换为字符串并打印出来。我想我可以构建我自己的函数,但肯定 Haskell 内置了一个函数来做到这一点。

回答by hammar

Indeed there is a built in function, aptly named print.

确实有一个内置函数,恰如其分地命名为print.

> print [1,2,3]
[1,2,3]

This is equivalent to putStrLn $ show [1,2,3].

这相当于putStrLn $ show [1,2,3].