0

I sucessfully compiled SML using the instructions from here and I try to execute this CML hello world program:

% cat cml_test.cm
Library
    structure Hello
is
    $cml/basis.cm
    $cml/cml.cm
    cml_test.sml

% cat cml_test.sml
structure Hello = struct
    open CML

    fun hello () = let
        val c : string chan = channel ()
        in
            spawn (fn () => TextIO.print (recv c));
            send (c, "Hello, world!\n");
            exit ()
        end

    fun main (_, argv) =
        RunCML.doit (fn () => ignore (spawn hello), NONE)
end

I tried to compile it like this:

% /work/smlnj/bin/ml-build /work/cml/cml_test.cm
Standard ML of New Jersey [Version 110.99.7.1; 64-bit; January 17, 2025]
[scanning /work/cml/cml_test.cm]
[library $cml/basis.cm is stable]
[library $cml/cml.cm is stable]
[library $cml/cml-internal.cm is stable]
[library $cml/core-cml.cm is stable]
[library $SMLNJ-BASIS/basis.cm is stable]
[library $SMLNJ-BASIS/(basis.cm):basis-common.cm is stable]
[loading /work/cml/(cml_test.cm):cml_test.sml]
[scanning 1756284-export.cm]
[scanning /work/cml/cml_test.cm]
[parsing (1756284-export.cm):1756284-export.sml]
[compiling (1756284-export.cm):1756284-export.sml]
1756284-export.sml:1.72-1.81 Error: unbound structure: Test in path Test.main
Compilation failed.

When I try to execute the print from REPL, it works:

% ./sml
Standard ML of New Jersey [Version 110.99.7.1; 64-bit; January 17, 2025]
- 1+2;
val it = 3 : int
- TextIO.print("hello\n");
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[library $SMLNJ-BASIS/(basis.cm):basis-common.cm is stable]
[autoloading done]
hello
val it = () : unit
-

Any help, please ?

1 Answer 1

1

The issue is just that ml-build expects you to specify a main function. If you don't specify it, it defaults to Test.main, which is why you are seeing the error "unbound structure: Test in path Test.main"

For your program, we need to tell it that the main function is called Hello.main.

This incantation works:

$ ml-build cml_test.cm Hello.main
$ sml @SMLload=cml_test
Hello, world!
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.