[Haskell-beginners] how to skip pattern match error when applying a mapM_

PICCA Frederic-Emmanuel frederic-emmanuel.picca at synchrotron-soleil.fr
Wed Jan 18 10:28:30 UTC 2017


Hello, thanks for the informations

after investigating, I could not switch  the IO and the Maybe
I need to process the IO in order to know if I have a Just or a Nothing
So this is a IO (Maybe ...)

I just would like to know if there is a better way to write this
knowing

len :: IO (Maybe Int)
get_position' :: a -> b -> IO (Maybe Double)

instance Frame DataFrameH5 where
  len d =  lenH5Dataspace (h5delta d)

  row d idx = do
    n' <- len d
    case n' of
      (Just n) -> do
        let eof = n - 1 == idx
        let nxs' = h5nxs d
        let mu = 0.0
        let komega = 0.0
        let kappa = 0.0
        let kphi = 0.0
        gamma' <- get_position' (h5gamma d) 0
        case gamma' of
          (Just gamma) -> do
            delta' <- get_position' (h5delta d) idx
            case delta' of
              (Just delta) -> do
                wavelength' <- get_position' (h5wavelength d) 0
                case wavelength' of
                  (Just wavelength) -> do
                    let source = Source (head wavelength *~ nano meter)
                    let positions = concat [mu, komega, kappa, kphi, gamma, delta]
                    -- print positions
                    let geometry =  Geometry K6c source positions Nothing
                    let detector = ZeroD
                    m <- geometryDetectorRotationGet geometry detector
                    poniext <- ponigen d (MyMatrix HklB m) idx
                    return $ Just DifTomoFrame { difTomoFrameNxs = nxs'
                                               , difTomoFrameIdx = idx
                                               , difTomoFrameEOF = eof
                                               , difTomoFrameGeometry = geometry
                                               , difTomoFramePoniExt = poniext
                                               }
                  Nothing -> return Nothing
              Nothing -> return Nothing
          Nothing -> return Nothing
      Nothing -> return Nothing
    where
      get_position' a b = do
        v <- get_position a b
        return $ if any isNaN v
                 then Nothing
                 else Just v


Thanks for your help

Frederic


More information about the Beginners mailing list