vesii
vesii

Reputation: 3128

Declaring a function without printing the signature [SML]

Is it possible to declare a function in SML without printing the signature?

I found out that you can print a string without printing val it = () : unit by doing:

val _ = print("Test1");

Is it possible to the same with functions? something like:

val _ = fun foo x = x + 5;
foo 10;

The following program won't compile in SML. I'm know that I can use let\local but then I can't use them outside the closure. Also I am looking for a way, without importing additional libraries.

Upvotes: 0

Views: 142

Answers (1)

sshine
sshine

Reputation: 16105

What you ask of relates only to the REPL, as function signatures are only printed in the REPL. You can avoid for functions (or other value declarations) to show up by defining them in a local scope, as you suggest (let, local or opaque struct).

A little hack is that multiple re-definitions in a row will yield the latest definition, but then you still need one at the end.

If you want to re-use a value in your code without the REPL printing it, perhaps you are looking to completely disable REPL declaration output, or run a compiled binary?

In Moscow ML you can run the REPL without declaration output with

mosml -quietdec file.sml

But with SML/NJ and others I don't know.

Upvotes: 2

Related Questions