InstallationΒΆ

Install on Windows:

winget install -e --id Diskuv.dk

or Apple/Silicon:

sudo curl -o /usr/local/bin/dk https://diskuv.com/a/dk-exe/2.4.202506160116-signed/dk-darwin_arm64
sudo chmod +x /usr/local/bin/dk

or Apple/Intel:

sudo curl -o /usr/local/bin/dk https://diskuv.com/a/dk-exe/2.4.202506160116-signed/dk-darwin_x86_64
sudo chmod +x /usr/local/bin/dk

or Linux with glibc and libstdc++ (Debian, Ubuntu, etc. but not Alpine):

sudo curl -o /usr/local/bin/dk https://diskuv.com/a/dk-exe/2.4.202506160116-signed/dk-linux_x86_64
sudo chmod +x /usr/local/bin/dk
[ -x /usr/bin/dnf ] && sudo dnf install -y libstdc++

Say: Make it soΒΆ

Copy and paste in your Terminal (PowerShell on Windows) and wait for a minute until you see Make it so.:

dk -g dune -U "Tr1Stdlib_V414Io.StdIo.print_endline {|Make it so.|}" Run

Run it again and it will be fairly quick:

dk -g dune -U "Tr1Stdlib_V414Io.StdIo.print_endline {|Make it so.|}" Run

Congratulations, you have run your first script!

Cross-compilingΒΆ

Now copy and paste and wait for several minutes (the first time only!):

dk -g dune -S "
    module Http = DkNet_Std.Http
    module Uri = Tr1Uri_Std.Uri
    let print_endline = Tr1Stdlib_V414Io.StdIo.print_endline
 " -U "
    print_endline @@
    Lwt_main.run @@
    Http.fetch_url ~max_sz:4096 @@
    Uri.of_string {|https://jigsaw.w3.org/HTTP/h-content-md5.html|}
 " -O ReleaseSmall Exe

What happened? You created standalone executables for Linux and Windows and Android, all with one command, and if you are on macOS you also created standalone macOS executables.

Go ahead and find the standalone executable for your machine, and then run it:

  • target/ZzZz_Zz.Adhoc-android_arm32v7a
  • target/ZzZz_Zz.Adhoc-android_arm64v8a
  • target/ZzZz_Zz.Adhoc-android_x86_64
  • target/ZzZz_Zz.Adhoc-darwin_arm64
  • target/ZzZz_Zz.Adhoc-darwin_x86_64
  • target/ZzZz_Zz.Adhoc-linux_x86
  • target/ZzZz_Zz.Adhoc-linux_x86_64
  • target/ZzZz_Zz.Adhoc-windows_x86_64.exe
  • target/ZzZz_Zz.Adhoc-windows_x86.exe

Using a script fileΒΆ

Let's save the last script to a file. Copy and paste the following (notice we use Run rather than -O ReleaseSmall Exe):

dk -g dune -S "
    module Http = DkNet_Std.Http
    module Uri = Tr1Uri_Std.Uri
    let print_endline = Tr1Stdlib_V414Io.StdIo.print_endline
 " -U "
    print_endline @@
    Lwt_main.run @@
    Http.fetch_url ~max_sz:4096 @@
    Uri.of_string {|https://jigsaw.w3.org/HTTP/h-content-md5.html|}
 " Run

You will see that it prints the contents for you (scroll up a bit):

module Http = DkNet_Std.Http
module Uri = Tr1Uri_Std.Uri

let print_endline = Tr1Stdlib_V414Io.StdIo.print_endline

let () =
    print_endline @@ Lwt_main.run
    @@ Http.fetch_url ~max_sz:4096
    @@ Uri.of_string {|https://jigsaw.w3.org/HTTP/h-content-md5.html|}

Put that into a file; let's name it myfirstscript.ml.

Then run it with:

dk -g dune -s myfirstscript.ml Run

Congratulations, you saved and ran your first script.

Next StepsΒΆ

You can: