首页 > 解决方案 > “无法加载模块'Control.Monad.State'它是隐藏包'mtl-2.2.2'的成员”使用runhaskell时出错

问题描述

我尝试运行runhaskell InterpretSpec.hs,然后从中提取Interpret.hs

-- Look at how testing is set up in FORTH project and emulate here
-- Make sure you unit test every function you write
import Test.Hspec
import Test.QuickCheck
import Control.Exception (evaluate)
import Pascal.Data
import Pascal.Interpret
import Control.Monad.State
import Data.Map (Map)
import qualified Data.Map as Map
main :: IO ()
main = hspec $ do
  let startscope=SymbolTable{variables=Map.empty, global=Map.empty, loop=["notrunning"], functions=Map.empty, procedures=Map.empty, returnstring="", inmain=True}
  describe "eval" $ do
    it "takes the square root" $ do
        evalState (eval(Op1 "sqrt" (Real1 25.0))) startscope `shouldBe` (5.0)
    it "takes the cos" $ do
        evalState (eval(Op1 "cos" (Real1 0.0))) startscope `shouldBe` (1.0)
    it "takes the sin" $ do
        evalState (eval(Op1 "sin" (Real1 0.0))) startscope `shouldBe` (0.0)
    it "takes the sin" $ do
        evalState (eval(Op1 "sin" (Real1 0.0))) startscope `shouldBe` (0.0)
    it "takes the sin" $ do
        evalState (eval(Op1 "sin" (Real1 0.0))) startscope `shouldBe` (0.0)

mtl 包含在.cabal文件中,我在以下位置引用了建议的解决方案:

也没有解决问题。

标签: haskellcabal

解决方案


就其本身而言,runhaskell不考虑您的阴谋集团环境。您必须通过以下方式使用它cabal exec

cabal exec runhaskell InterpretSpec.hs

推荐阅读