Running a main functionls
Unison programs can be executed within theUCMwith therun
command. This command is used to execute the "main" entry point to your Unison code. Therun
command expects adelayed computationwhich returns unit or()
.Therun
command provides a handler for theIO
andException
abilities, so programs which perform IO and bubble up top-level failures can be executed by the UCM.
Arguments to main functions
To accept arguments to the entry point of your Unison program, you can use thegetArgs
function:getArgs : '{IO, Exception} [Text]
.
getArgs
returns a list ofText
representing the arguments of the program in a thunk or delayed computation. Remember to force the thunk with the!
when you actually want the arguments to work with.
The following function will print out the given main function arguments:
In the UCM, you can call it withrun
like
.> run myMain blah blah blah
And it will return the following to the console:
.> run myMain blah blah blah
Hello blah blah blah
Stand-alone binaries
The UCM can produce standalone binary executables for when you want to run a Unison program without entering into the CLI! These binary executables contain all the Unison code for the program in questionANDits essential dependencies in a single, lightweight bytecode file.
Toproducethe binary file run thecompile
command from within the UCM:
.> compile myMain myRadExecutable
The first argument is the entry point to your Unison program (the "main" method described above), and the second argument is the name of the executable file that the UCM should produce.
Unison executable files have the suffix.uc
so the above command will write a file calledmyRadExecutable.uc
in the folder where the codebase lives.
Torunthe binary executable, you can then issue the following command from the terminal of your choice:
$ ucm run.compiled myRadExecutable.uc
The arguments supplied to this are
🌻 Your Unison program is now up and running!