haskell - Invert Return Value of Type IO Bool -


i have function returns type io bool. i'd use function argument filterm, want invert output. i've tried effect of (not . f), not isn't hip io vibe. how can invert io bool?

here's minimal working example:

#!/usr/bin/env runhaskell {-# language unicodesyntax #-} module main import prelude.unicode  userenteredstr ∷ string → io bool userenteredstr str =     input ← getline     return (input ≡ str)  -- doesn't work. how write function?  --userdidntenterstr ∷ string → io bool --userdidntenterstr str = not . userenteredstr  main = result ← userenteredstr "y"           print result 

sorry if basic! can't find function on hoogle type io bool -> io bool , haven't found in web searching.

for record, "doesn't work" not helpful error description :) syntax error? type error? compile , typecheck, return wrong value? it's vague description of problem possible...and really big impairment/hurdle wants you.

the main problem here can't apply not io bool, because not works on bools. io bool not bool, nor "contain bool", it's not surprising doesn't work. it's trying apply (* 2) dog. dog isn't number!

but seems know how work notation , binding io, maybe can understand why work?

userdidntenterstr :: string -> io bool userdidntenterstr str =    didenter <- userenteredstr str    return (not didenter) 

alternatively, can apply (a -> b) result of io a new io b using fmap:

userdidntenterstr :: string -> io bool userdidntenterstr str = fmap not (userenteredstr str) 

Comments