Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I print a list in haskell?

Tags:

string

io

haskell

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.

like image 559
Alexander Bird Avatar asked May 10 '11 15:05

Alexander Bird


People also ask

How do I display lists in Haskell?

Example #1print("Demo to show list in Haskell !!") let list1 = [100, 50, 235, 167, 345, 909, 675, 20] let list2 = [1, 2, 3, 4, 5, 6, 7, 8, 9] let list3 = [1.1, 2.2, 3.3, 4.4, 5.5, 6.6] let list4 = [5, 10, 15, 20, 15, 30, 35, 40] let list5 = [123.4, 567.9, 56.0, 3.9, 76.9] print("printing list element !!")

How do I print statements in Haskell?

If you have a String that you want to print to the screen, you should use putStrLn . If you have something other than a String that you want to print, you should use print . Look at the types! putStrLn :: String -> IO () and print :: Show a => a -> IO () .


1 Answers

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

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

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

like image 196
hammar Avatar answered Oct 05 '22 16:10

hammar