首页 > 解决方案 > 使用导出的符号

问题描述

我有一个名为 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 消除.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)  "",
  |                 ^^^^^^

我可能错过了一些非常基本的东西。任何想法 ?谢谢!

标签: haskellmodule

解决方案


module MaxFlow 
   (...,Vertex,...) where

这表示您要导出命名的类型Vertex,而不是数据构造函数或字段。您可能想要的是导出数据类型和数据构造函数:

module MaxFlow (Vertex(Vertex)) where

或者导出类型、所有数据构造函数和所有字段:

module MaxFlow (Vertex(..)) where

这些点是字面意思而不是简写,您可以Vertex(..)在导出列表中键入以表示类型、数据构造函数和所有字段。


推荐阅读