我有一个名为maxflow.hs的Haskell文件,它导出几个符号
module MaxFlow
(solveMaxFlow,MaxFlowNet,Vertex,Graph) where
import Data.List
data Vertex = Vertex {
vertexLabel :: String
, vertexNeighbors :: [(String,Int)]
, vertexDistance :: Int
, vertexPredecessor :: String
} deriving (Show)
....在同一个目录中,我有另一个名为elimination.hs的文件,试图使用这些符号之一。
import MaxFlow
g = [
Vertex "0" [("1",16), ("2",13) ] (maxBound::Int) "",
Vertex "1" [("2",10), ("3",12) ] (maxBound::Int) "",
Vertex "2" [("4",14) ,("1",4) ] (maxBound::Int) "" ,
Vertex "3" [ ("5",20), ("2",9)] (maxBound::Int) "" ,
Vertex "4" [("5",4), ("3",7) ] (maxBound::Int) "" ,
Vertex "5" [ ] (maxBound::Int) ""
]但出于某种原因我不能加载这个文件。运行:l elimination.hs
我得到了
elimination.hs:4:17: error:
Data constructor not in scope:
Vertex :: [Char] -> [([Char], Integer)] -> Int -> [Char] -> a
|
4 | Vertex "0" [("1",16), ("2",13) ] (maxBound::Int) "",
| ^^^^^^我可能错过了一些非常基本的东西。知道吗?谢谢!
发布于 2020-03-15 22:32:07
module MaxFlow
(...,Vertex,...) where这表示您希望导出名为的类型Vertex,而不是数据构造函数或字段。您可能需要的是同时导出数据类型和数据构造函数:
module MaxFlow (Vertex(Vertex)) where或导出类型、所有数据构造函数和所有字段:
module MaxFlow (Vertex(..)) where这些点是字面的而不是短手,您可以在导出列表中键入Vertex(..)来表示类型、数据构造函数和所有字段。
https://stackoverflow.com/questions/60698299
复制相似问题