Runtime Haskell interpreter

#7GHC Warnings propagate as exceptions from runInterpreter

Hi, when compiling program which gets warning inside runInterpreter, I got

GHC returned a result but said: [GhcError {errMsg = "student30293.hs:6:24:Pattern match(es) are overlappedIn an equation for 216ack217:ack 0 n = ...ack m 0 = ...ack m n = ..."}]

It is very unfortunate that compilation errors are propagated as return value but warnings as exception.

    • description updated
  • Could you provide a case to reproduce?

  • I'll try to provide a case for this error, just substitute the function testHint in your example file with this one:

    testHint :: Interpreter ()
    testHint = do
      setImportsQ [("Control.Lens", Nothing)]
      say =<< typeOf "(^.)"
      say =<< typeOf "mapOf"
  • It would suffice to modify this function in Hint.Base:

    mayFail :: MonadInterpreter m => m (Maybe a) -> m a
    mayFail action =
        do
            maybe_res <- action
            --
            es <- modifySessionRef ghcErrListRef (const [])
            --
            case (maybe_res, null es) of
                (Nothing,True)  -> throwError $ UnknownError "Got no error message"
                (Nothing,False) -> throwError $ WontCompile (reverse es)
                (Just a, True)  -> return a
                (Just _, False) -> fail $ "GHC returned a result but said: " ++ show es

    handling differently the last case. What problems do you expect if the last line is substituted with:

    (Just a, False)  -> return a    --  ?

    What other errors are possible?

  • hint is now on GitHub, feel free to open this issue over there or open pull requests with patches:

    https://github.com/mvdan/hint