[Haskell-cafe] MonadThrow and Either instance

PICCA Frederic-Emmanuel frederic-emmanuel.picca at synchrotron-soleil.fr
Thu Feb 6 15:30:15 UTC 2020


Hello,

I try to parse a config file and extract a (Path Abs Dir) from these files

So I have a parser as defined in config-ini

So I need a function with this signature

pathAbsDir :: Text -> Either String (Path Abs Dir)
pathAbsDir t = do
  d <- try $ parseAbsDir (unpack . uncomment $ t)
  case d of
    Right v -> Right v
    Left e  -> Left (show e)

since I am using parseAbsDir wi this signature

parseAbsDir :: MonadThrow m => FilePath -> m (Path Abs Dir) 

I would like to know how to write the patAbsDir method

for now I have this error message

src/Hkl/Binoculars/Config.hs:82:8-49: error:
    • Couldn't match type ‘[Char]’ with ‘GHC.Exception.SomeException’
        arising from a use of ‘try’
    • In a stmt of a 'do' block:
        d <- try $ parseAbsDir (unpack . uncomment $ t)
      In the expression:
        do d <- try $ parseAbsDir (unpack . uncomment $ t)
           case d of
             Right v -> Right v
             Left e -> Left (show e)
      In an equation for ‘pathAbsDir’:
          pathAbsDir t
            = do d <- try $ parseAbsDir (unpack . uncomment $ t)
                 case d of
                   Right v -> Right v
                   Left e -> Left (show e)
   |
82 |   d <- try $ parseAbsDir (unpack . uncomment $ t)
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


I understand that the MonadThrow instance of Either is for Either Exception a

But I want (Either String a).


Cheers


Frederic


More information about the Haskell-Cafe mailing list