在 CM 文件中使用的文件中使用 HashTable 结构时出错

问题描述 投票:0回答:1

我正在使用 CM 文件“build.cm”来编译我的 sml 文件。在文件 symbol_table.sml 中,我使用了 sml 基础库中的结构 HashTable。运行 CM 文件时,我收到一条错误消息,提示 HashTable is an unbounded structure

symbol_table.sml


signature SYMTABLE =
sig
val table : (string,Rational.rational) HashTable.hash_table ;
val add_entry : string * Rational.rational -> unit ;
val lookup_entry : string -> Rational.rational
end ;

structure SymTable : SYMTABLE  =
struct
open Rational ; 
open HashTable ; 
(* raised when I do a lookup and can't find something *)
exception lookup_error

val hash_fn : string->word = HashString.hashString

fun cmp_fn(x : string ,y : string) = (x = y)


val init_sz : int = 101

val table: (string,rational) hash_table = mkTable (hash_fn, cmp_fn)(init_sz, lookup_error)
fun add_entry(key, value) = insert table (key,value) ;
fun lookup_entry(key) = lookup table key ;

end ;

build.cm

Library 
    structure compile
is 
    $/basis.cm 
    $/ml-yacc-lib.cm 
    $/smlnj-lib.cm
    $smlnj/compiler/compiler.cm

    bigint.sml
    rational.sml
    symbol_table.sml 
    calc.lex 
    calc.yacc: MLYacc
    glue.sml 
    compiler.sml

错误信息-

Standard ML of New Jersey v110.79 [built: Sat Oct 26 12:27:04 2019]
- CM.make "build.cm" ;
[autoloading]
[library $smlnj/cm/cm.cm is stable]
[library $smlnj/internal/cm-sig-lib.cm is stable]
[library $/pgraph.cm is stable]
[library $smlnj/internal/srcpath-lib.cm is stable]
[library $SMLNJ-BASIS/basis.cm is stable]
[library $SMLNJ-BASIS/(basis.cm):basis-common.cm is stable]
[autoloading done]
[scanning build.cm]
[parsing (build.cm):symbol_table.sml]
[attempting to load plugin $/lex-ext.cm]
[library $/lex-ext.cm is stable]
[library $smlnj/cm/tools.cm is stable]
[library $smlnj/internal/cm-lib.cm is stable]
[plugin $/lex-ext.cm loaded successfully]
[attempting to load plugin $/mllex-tool.cm]
[library $/mllex-tool.cm is stable]
[plugin $/mllex-tool.cm loaded successfully]
[attempting to load plugin $/mlyacc-tool.cm]
[library $/mlyacc-tool.cm is stable]
[plugin $/mlyacc-tool.cm loaded successfully]
[library $/ml-yacc-lib.cm is stable]
[library $smlnj/compiler/compiler.cm is stable]
[library $SMLNJ-ML-YACC-LIB/ml-yacc-lib.cm is stable]
[loading (build.cm):bigint.sml]
[loading (build.cm):rational.sml]
[compiling (build.cm):symbol_table.sml]
symbol_table.sml:6.43-6.63 Error: unbound structure: HashTable in path HashTable.hash_table
symbol_table.sml:14.3-14.17 Error: unbound structure: HashTable
val it = false : bool

Rational是rational.sml中定义的结构,compile是compile.sml中定义的结构

我在网上查看了 CM 文件的文档,但找不到任何有用的信息。另外,我是 sml 的新手,因此无法想出任何直接的方法来修复此错误。我也有第一次使用 CM 文件的经验。任何帮助将不胜感激。

smlnj cm
1个回答
0
投票

这应该有效。我做了一个小的简化编辑(主要是用 int 替换 Rational.rational 并且在 build.cm 文件中只有“$/smlnj-lib.cm”)并且示例代码编译没有错误 [HastTable 在 smlnj-lib 库中,而不是基础图书馆]。

不要使用像

这样的规格

$smlnj/编译器/compiler.cm

在您的 CM 描述文件中。这通常是行不通的,至少在这个时候是这样。

这个问题中一个明显的未知数是你使用的是什么版本的 SML/NJ。我使用 110.99.3(“旧”版本)和 2022.1(“开发”版本)。

© www.soinside.com 2019 - 2024. All rights reserved.