haskell, how to unwrap IO monad -
this question has answer here:
- how normal value io action in haskell 2 answers
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
Post a Comment