1

I am using a CM file "build.cm" to compile my sml files. In the file symbol_table.sml, I have used the structure HashTable from the sml basis library. When the CM file is run, I receive an error saying 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

error message -

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 is a structure defined in rational.sml and compile is a structure defined in compile.sml

I looked online at the documentation of CM files but couldn't find anything helpful. Also, I am new to sml, thus can't figure out any straightforward way of fixing this error. I also have first time experience of working with CM files. Any help would be appreciated.

Aaveg jain
  • 11
  • 2
  • There should be a couple of lines about loading "$/smlnj-lib.cm" in the output, but I can't think of any other reason for this issue than using a different "build.cm" from the one you think you're using. – molbdnilo Mar 17 '23 at 12:40

1 Answers1

0

This should work. I made some minor simplifying edits (mainly replacing Rational.rational with int and having only "$/smlnj-lib.cm” in the build.cm file) and the example code compiled without error [HashTable is in the smlnj-lib library, not the Basis library].

Do not use specs like

  $smlnj/compiler/compiler.cm

in your CM description files. This will generally not work, at least at this time.

An obvious unknown in this question is what version of SML/NJ you were using. I used 110.99.3 (the "legacy" version) and 2022.1 (the current "development" version).

DBM
  • 11
  • 3