[Haskell-cafe] IO Monad operation madness

Isaac Dupree isaacdupree at charter.net
Thu May 17 18:49:15 EDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> linkedListToHaskellStringList :: LinkedList -> IO [String]
> linkedListToHaskellStringList listPtr =
>     let convertList' ptr =
convertList' :: LinkedList -> [IO String], I infer?
>         if listIsNull ptr
>             then
>                 []
>             else
are you doing IO here or not? You need a 'do' if you are (else this is a
syntax error), but IO /= [], so what is the function returning?
>                 let str = peekCString =<< (linked_list_getdata ptr)
>                 next <- linked_list_next ptr
>                 str : (convertList' next)
>     in
>         sequence $ convertList' listPtr
> 
> listIsNull :: LinkedList -> Bool
> listIsNull (LinkedList ptr) = ptr == nullPtr

I'd recommend recursion without the 'sequence', I think, so you can do
IO along the way - traversing the LinkedList - and then 'return' the
list made from (:).  (and throw in unsafeInterleaveIO if you're feeling
sadistical and want parts of the traversal to be performed at
unspecified later dates)

Isaac
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGTNvrHgcxvIWYTTURAr9NAKDEwWAtae3OfVf8I/Aqgwnuq4g9LgCgvu0F
FTB0hdr7tYaf/6PElVNY+6Y=
=EtHd
-----END PGP SIGNATURE-----


More information about the Haskell-Cafe mailing list