haskell - 使用导出的符号
问题描述
我有一个名为 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) "",
| ^^^^^^
我可能错过了一些非常基本的东西。任何想法 ?谢谢!
解决方案
module MaxFlow
(...,Vertex,...) where
这表示您要导出命名的类型Vertex
,而不是数据构造函数或字段。您可能想要的是导出数据类型和数据构造函数:
module MaxFlow (Vertex(Vertex)) where
或者导出类型、所有数据构造函数和所有字段:
module MaxFlow (Vertex(..)) where
这些点是字面意思而不是简写,您可以Vertex(..)
在导出列表中键入以表示类型、数据构造函数和所有字段。
推荐阅读
- c - 以乘法格式显示的素数因子
- argparse - 你如何为 python 模块的 argparse 编写 unittest?
- python - Gradient Boosting 分类器 - scikit 中训练数据的准确性
- django - 如何在 Django 中使用相同的 url
- java - 使用循环接受额外的用户输入,直到用户输入一个结束输入的值
- docker - 在 Laradock 中 Ghostscript 版本没有变化
- ruby - 安装 ruby-2.0.0 时出错
- webpack - webpack 中的 main.js 路径自动注入错误
- android - 使用分屏创建 Android 视频流应用
- javascript - Mailchimp API /列出merge_fields的日期类型参数格式