haskell, how to unwrap IO monad -


this question has answer here:

i can do: runidentity, runerrort , more unwrap inner monad.
however, should in case of io (either string int) ? how unwrap ?

you not unwrap io a actions. instead, include them in main action (which has io type, hence can use such actions) , compiler ensures main executed.

you may teach functions not understand io how handle io; example, have:

fmap  :: (a ->    b) -> io -> io b (=<<) :: (a -> io b) -> io -> io b 

thus if have function consumes either string int, may use 1 of above functions teach how consume io (either string int) instead.

for further reading, may enjoy the io monad people don't care. (i monad tutorials you have invented monads! (and maybe have.) , all monads, though less directly relevant question.)


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -