Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to display IO [t0] values

20 views
Skip to first unread message

dinesh...@gmail.com

unread,
Nov 9, 2014, 10:34:25 AM11/9/14
to
Hello all,
I am new to Haskell and would like to know how to write a function to take an IO [t0] as input and display the values. Its a bit confusing regarding int and IO int in Haskell

Gene Arthur

unread,
Feb 7, 2015, 1:52:48 PM2/7/15
to
quick and dirty way, define putStrLnIO = (=>> putStrLn) in ghci and then:
putStrLnIO . getline

Being you are new what is happening is that >>= is the bind operator and since IO is a monad, you are by binding/lifting the StringIO value into the internal world of the IO monad where the value is dropped down to it's base type of String and a regular old putStrLn can be used. Another way of looking at is that the StringIO is lifted into the context of the container monad, so there is besides that weird looking operator >>= , you also have a function, liftM that you may use in the definition of putStrLnIO:
putStrLnIO = liftM putStrLn

You can do this raw without defining new functions:

getline >>= putStrLn
OR
liftM putStrLn . getline

My hope is that you will try these and also look at the 'do notation way of doing this too.' leave that for another commenter that likes more verbage and pseudo variables, and pointed rather point free function definitions.

cheers gene
0 new messages