
Hello, Here a reduction of my problem values :: IO [IO (Maybe Int)] values = do let v = [Just 1, Just 2, Just 3, Nothing, Just 5, Nothing, Just 7] :: [Maybe Int] return $ map return v main :: IO () main = do vs <- values nvs <- mapM_ go vs print nvs where go :: IO (Maybe Int) -> IO Int go v' = do Just v <- v' return v when I run this script, I get a runtime error picca@diffabs6:~/tmp$ runhaskell test.hs test.hs: user error (Pattern match failure in do expression at test.hs:13:10-15) What I want is a go method which skip silently the (IO Nothing) values. so when used in the mapM_ it return only the values which are returned by the IO (Maybe Int) (stored in the values) Thanks for your help Frédéric Indeed

PICCA Frederic-Emmanuel
Hello,
Here a reduction of my problem
values :: IO [IO (Maybe Int)] values = do let v = [Just 1, Just 2, Just 3, Nothing, Just 5, Nothing, Just 7] :: [Maybe Int]
I would let the compiler deal with the type, i.e. skip the ` :: [Maybe Int]`.
return $ map return v
Wrapping the list *and* its items in `IO` seems excessive. Would it not be easier to have `values :: IO [Maybe Int]`?
main :: IO () main = do vs <- values nvs <- mapM_ go vs print nvs where go :: IO (Maybe Int) -> IO Int go v' = do Just v <- v' return v
when I run this script, I get a runtime error
picca@diffabs6:~/tmp$ runhaskell test.hs test.hs: user error (Pattern match failure in do expression at test.hs:13:10-15)
What I want is a go method which skip silently the (IO Nothing) values. so when used in the mapM_ it return only the values which are returned by the IO (Maybe Int) (stored in the values)
You can't, not with the route you've taken here. It would be the equivalent of skipping the `else` clause of an `if` statement. I suggest you rethink your approach of how to remove (filter out) the `Nothing` items in the list. /M -- Magnus Therning OpenPGP: 0x927912051716CE39 email: magnus@therning.org jabber: magnus@therning.org twitter: magthe http://therning.org/magnus Increasingly, people seem to misinterpret complexity as sophistication, which is baffling—the incomprehensible should cause suspicion rather than admiration. — Niklaus Wirth

Hello thanks for your time.
I would let the compiler deal with the type, i.e. skip the ` :: [Maybe Int]`.
It was just a reduced example of my real problem. And I wanted to express the type for th ehuman of the mailing list :)
Wrapping the list *and* its items in `IO` seems excessive. Would it not be easier to have `values :: IO [Maybe Int]`?
No because the Maybe Int comes from an IO. But we solved the problem using the MaybeT MaybeT IO MyDataType So as you said, I rethink this with the help of the mailing list guyes. Thansk a lot Frederic
participants (2)
-
Magnus Therning
-
PICCA Frederic-Emmanuel