Take the 2-minute tour ×

How do I print a list to stdout in 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.

share|improve this question
are you used to another programming language? which one? I find it a bit surprising that someone wouldn't expect print to exist.. –  yairchu May 10 '11 at 22:38

1 Answer 1

up vote 15 down vote accepted

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

> print [1,2,3]

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

share|improve this answer
Indeed, print works on anything that can be shown. –  Dan Burton May 10 '11 at 16:13
Following up on what @Dan said, anything that implements the Show TypeClass has a default printable representation. –  Daniel May 11 '11 at 12:41
How would I do it in case the list was not of standard type like Int but of custom type (Eg: type Height = Int) –  bikashg May 22 '11 at 9:03
@Bikash: As long as the contained type is an instance of Show, it will work fine. type Height = Int does not create a custom type, only an alias, so it behaves exactly as if you'd used Ints. –  hammar May 22 '11 at 9:27

Your Answer


