[Haskell-beginners] (no subject)

PICCA Frederic-Emmanuel frederic-emmanuel.picca at synchrotron-soleil.fr
Tue Jan 17 10:15:24 UTC 2017


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 at 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


More information about the Beginners mailing list