io - Haskell monad return type -


i'm trying bit of programming , can't monads. i've advanced bit io functions, i'm lost...

i've got xml string loaded network (so it's "stored" in io string). because of this, need do block load common string.

foo :: io string -> nothing foo xmlio =     xmlio <- xml     -- magic 

i've implemented function takes pure string , returns pure xml element. bit more, let's simplify it's not important question.

import text.xml.light import text.xml.light.input  toxml :: string -> maybe element toxml s = parsexmldoc s 

now tried combine these 2 accept io string , return "io element".

toxmlio :: io string -> ??? maybe element toxmlio s =     pures <- s     let toreturn = parsexmldoc s     return s 

the return function's type (according ghci) :

let foo = "<foo>bar</foo>" :t return (parsexmldoc foo)     >> return (parsexmldoc foo) :: monad m => m (maybe element) 

but if change header of function

toxmlio :: io string -> monad (maybe element) toxmlio s =     pures <- s     let toreturn = parsexmldoc s     return s 

i compilation error

kind mis-match first argument of `monad' should have kind `* -> *', `maybe element' has kind `*' in type signature `xmlio':   xmlio :: string -> monad (maybe element) 

does have idea how solve issue? or lost , haskell way? thank answer.

it looks want:

toxmlio :: io string -> io (maybe element) toxmlio s =     pures <- s     let toreturn = parsexmldoc pures     return toreturn 

however can use liftm:

toxmlio :: io string -> io (maybe element) toxmlio = liftm parsexmldoc 

you make more general, since liftm not depend on particular monad type:

toxmlio :: monad m => m string -> m (maybe element) toxmlio = liftm parsexmldoc 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -