相同的数据结构导入两次,无法访问基础数据

时间:2014-04-22 08:07:21

标签: haskell

我正在尝试使用SourcePos获取sourceline之外的行号 所以我导入了Text.Parsec.Pos(SourcePos,sourceLine)。 但是,另一个创建Language.ECMAScript3.Syntax的模块(SourcePos)会导出为自己的类型,但不会导出sourceLine

这没有帮助。我收到此错误:src \ Main.hs:62:53:

Couldn't match type `Text.Parsec.Pos.SourcePos'
              with `Language.ECMAScript3.Syntax.SourcePos'
Expected type: JavaScript Language.ECMAScript3.Syntax.SourcePos
               -> [Char]
  Actual type: JavaScript Text.Parsec.Pos.SourcePos -> [Char]    ....
list (one:rest) = case one of
      (VarDeclStmt _ [VarDecl _ (Id ln a) _]) -> "\nvar "++  (show  (sourceLine (ln)) )  ++ (show a)++ list rest
      otherwise -> list rest

更大的背景:

 lookAtJsModule src label func =
     case parseFromString src of
        Left err -> "Can't parse a test-case: " ++
                                    "\nThe error was " ++ (show err)
        Right js -> label ++ (func js)


    list0 tree = case tree of
        (Script a b)   -> list b

    --list :: [Language.ECMAScript3.Syntax.Statement a] -> String

    list (one:rest) = case one of
          (VarDeclStmt _ [VarDecl _ (Id (ln ) a) _]) -> "\nvar "++  (show  ((ln  )) )  ++ (show a)++ list rest
          otherwise -> list rest

    list[] = ""


    listSpecificModule src = lookAtJsModule src "list:" list0

listVars _ = do
  content <- getContents

putStrLn(listSpecificModule content)0

注意它是相同的&#34;事物&#34;。是否有办法,例如演员来解决这个问题?

1 个答案:

答案 0 :(得分:2)

您可以尝试使用合格的导入来解决此问题。例如:

import qualified Text.Parsec.Pos as PP
import qualified Language.ECMAScript3.Syntax as ES

然后你可以从这些模块中引用函数或类型/值构造函数,如下所示:

-- function from Text.Parsec.Pos
PP.function

-- function from Language.ECMAScript3.Syntax
ES.function