[Haskell-beginners] MonadThrow, MonadReader and shake

PICCA Frederic-Emmanuel frederic-emmanuel.picca at synchrotron-soleil.fr
Thu Dec 13 09:15:41 UTC 2018


Hello,

I try to write this sort of code

xdsme' :: SomeDataCollection
       -> Maybe Cell
       -> Maybe SpaceGroup
       -> GZiped
       -> [Path Abs File]
       -> ReaderT Beamline IO ()
xdsme' c@(SomeDataCollection SCollect SHdf5 _) cell sg z is = do
  -- xdsme compute the output path by himself.
  cwd' <- toProcessDataPath c
  rdir <- resultsPrefixFile xdsMePrefix c
  dir <- resultsPrefixDir ("xdsme_" ++ xdsMePrefix) c
  dir' <- resultsPrefixFile "" c
  xmlPath <- parseRelFile $ toFilePath dir' ++ "_xdsme.xml"
  xml <- parseAbsFile $ toFilePath cwd' </> toFilePath dir </> toFilePath xmlPath
  uploadedPath <- parseRelFile $ toFilePath dir' ++ "_xdsme.uploaded"
  uploaded <- parseAbsFile $ toFilePath cwd' </> toFilePath dir </> toFilePath uploadedPath

  let shakeFiles' = toFilePath cwd' </> toFilePath dir </> ".shake/"
  let images = getImages c z

  liftIO $ shake shakeOptions{ shakeFiles=shakeFiles'
                    , shakeReport=["/tmp/shake.html"]
                    , shakeVerbosity=Diagnostic} $ do
    want [toFilePath uploaded]

    -- execute xdsme and deal with input dependencies
    toFilePath xml %> \_out -> do
      need (map toFilePath is)
      processXdsMe cwd' cell sg rdir images

    toFilePath uploaded %> \_out -> do
      need [toFilePath xml]

      container <- liftIO . fromFile . toFilePath $ xml

      -- post processing
      let attachment = _autoProcProgramAttachment . _autoProcProgramContainer $ container

      attachment' <- toRuchePath attachment         <- HERE PROBLEM

      _ <- copyAttachment' attachment attachment'

      let container' = (autoProcProgramContainer . autoProcProgramAttachment .~ attachment') container -- replace attachement

      -- upload into ISPYB
      liftIO $ storeAutoProcIntoISPyB c NoAnomalous container'
      cmd_ ("touch" :: String) (toFilePath uploaded)


where

toRuchePath :: (MonadReader Beamline m, MonadThrow m)
            => [AutoProcProgramAttachment WithPrefix]
            -> m [AutoProcProgramAttachment ISPyB]
toRuchePath = mapM go
    where
      go :: (MonadReader Beamline m, MonadThrow m)
         => AutoProcProgramAttachment WithPrefix
         -> m (AutoProcProgramAttachment ISPyB)
      go a = do
        (d, _) <- toPath a
        b <- ask
        newd <- mkText255 . pack . toRuchePath' b . fromAbsDir $ d
        return a {filePath = newd}


but when I try to compile this I get this error.
How can I teach ghc how to solve this issue ?

thanks for your help

Frederic

src/XdsMe.hs:211:22-43: error:
    • Could not deduce (MonadThrow Action)
        arising from a use of ‘toRuchePath’
      from the context: t ~ 'Collect
        bound by a pattern with constructor:
                   SCollect :: SCollectType 'Collect,
                 in an equation for ‘xdsme'’
        at src/XdsMe.hs:180:30-37
      or from: f ~ 'ISPyB.DataCollection.Hdf5
        bound by a pattern with constructor:
                   SHdf5 :: SCollectSourceFormat 'ISPyB.DataCollection.Hdf5,
                 in an equation for ‘xdsme'’
        at src/XdsMe.hs:180:39-43
    • In a stmt of a 'do' block: attachment' <- toRuchePath attachment
      In the expression:
        do { need [toFilePath xml];
             container <- liftIO . fromFile . toFilePath $ xml;
             let attachment
                   = _autoProcProgramAttachment . _autoProcProgramContainer
                     $ container;
             attachment' <- toRuchePath attachment;
             .... }
      In the second argument of ‘(%>)’, namely
        ‘\ _out
           -> do { need [...];
                   container <- liftIO . fromFile . toFilePath $ xml;
                   .... }’


More information about the Beginners mailing list