我正在尝试编译Polysemy https://hackage.haskell.org/package/polysemy-1.2.3.0/docs/Polysemy.html运行时使用 Hint (语言.Haskell.解释器 https://hackage.haskell.org/package/hint-0.9.0.2/docs/Language-Haskell-Interpreter.html).
当我尝试这样做时,我确实收到了有关使用不当的错误:
“交互式”代码中的运算符;传递给 GHC 的文本提示似乎有语法错误。
{-# LANGUAGE DataKinds #-}
module Main where
import Polysemy (Embed, embed, runM, Sem)
import Language.Haskell.Interpreter (as, interpret, Interpreter, runInterpreter, setImportsQ)
import Data.Typeable (typeOf)
import Control.Monad.IO.Class (liftIO)
main :: IO ()
main = do
-- Hint works fine to interpret a String:
m <- interpretWithErrors exampleHint
print m
-- And Sem works fine:
runM exampleSem
-- But notice the weird detected type:
print $ typeOf exampleSem
-- And now Hint fails to interpret a Sem:
s <- interpretWithErrors exampleBoth
print $ typeOf s
runM s
type MyEffect = Sem '[Embed IO] ()
exampleSem :: MyEffect
exampleSem = embed $ print "Successful Sem!"
exampleHint :: Interpreter String
exampleHint = do
setImportsQ [("Prelude", Nothing)]
interpret "\"Successful Hint!\"" (as :: String)
exampleBoth :: Interpreter MyEffect
exampleBoth = do
setImportsQ [("Prelude", Nothing), ("Polysemy", Nothing)]
liftIO $ print "Successfully imported!"
-- This is where it fails:
s <- interpret "embed $ print \"Success!\"" (as :: MyEffect)
liftIO $ print "Successfully interpreted!"
return s
interpretWithErrors :: Interpreter a -> IO a
interpretWithErrors i_a = do
e_e_a <- runInterpreter i_a
either (ioError . userError . show) (return) e_e_a
运行上面的打印:
"Successful Hint!"
"Successful Sem!"
Sem (': ((* -> *) -> * -> *) (Embed IO) ('[] ((* -> *) -> * -> *))) ()
"Successfully imported!"
Hint-Polysemy: user error (WontCompile [GhcError {errMsg = "<interactive>:3:41: error: Operator applied to too few arguments: :"}])
一些注意事项:
- 我正在使用 cabal,为了通过
import
解释器 monad 中的行我必须从 cabal 沙箱 shell 中运行它,因为 Polysemy 没有安装到我的机器上。
- 也就是说,我不认为阴谋集团或进口一词多义是问题所在。如果我只是忽略导入 Polysemy 并且只是
setImportsQ [("Prelude", Nothing)]
.
- 我正在解释的字符串甚至不需要是有效的表达式;我可以在其中添加胡言乱语而不改变错误。这向我表明问题出在
(as :: MyEffect)
.
- 我包括
typeOf
证明MyEffect
事实上是Typeable
.
- 我不知道为什么
typeOf exampleSem
给出了如此长而奇怪的类型签名。我确实认为这在某种程度上是问题所在。重新排列MyEffect
to type MyEffect = Sem ((Embed IO) : []) ()
没有影响。
如果我做错了什么,任何人都清楚吗?我应该如何尝试调试这个问题?
假设这是提示、一词多义或(不太可能)中的错误Type.Reflection.Typeable https://hackage.haskell.org/package/base-4.12.0.0/docs/Type-Reflection.html#t:Typeable,我的下一步将尝试修复它?我想我必须以某种方式确定哪个库有问题?
这是对先前问题的改进。这是原文。 https://stackoverflow.com/questions/59446654/debug-ghc-compilation-error-returned-at-runtime-by-hints-language-haskell-inte