[Haskell-cafe] cpphs calls error when it finds an #error declaration

Malcolm Wallace malcolm.wallace at me.com
Wed Aug 28 17:43:33 CEST 2013


On 27 Aug 2013, at 08:33, Niklas Hambüchen wrote:

> @Malcolm, would you mind a change towards throwing an exception that is
> different from error so that it can be easily caught, or even better, a
> change from
> 
>    runCpphs :: ... -> IO String
> 
> to
> 
>    runCpphs :: ... -> IO (Either String String)
> 
> or similar?

Have you tried simply wrapping the call to runCpphs in a "catch"?  Something like

    safeRunCpphs :: ... -> IO (Either String String)
    safeRunCpphs foo = fmap Right (runCpphs foo) `catch` (\(UserError s)-> Left s

> If an exception based interface is kept, it would be nice to add some
> haddock to `runCpphs`; not knowing about the existence of #error, it is
> easy to assume that the IO is only used for accessing the FilePath
> passed in.

The IO is used also for reading #include'd files, of course.  I'd be happy to add some extra documentation making the behaviour on #error clearer, if you can suggest some text that would have helped you.

Regards,
    Malcolm



More information about the Haskell-Cafe mailing list