2014-04-22 66 views
0

我試圖用sourceline 於是我進口Text.Parsec.Pos(SourcePos,sourceLine)走出SourcePos的行號。 但是,創建SourcePos的另一個模塊(Language.ECMAScript3.Syntax)以其自己的類型導出,但不導出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內容)0

注意它是一樣」。有辦法,例如投下來解決這個問題?

+0

你能證明傳給你的錯誤的代碼? – dfeuer

+0

我添加了代碼。 – Aftershock

+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