Show HN: dk – A script runner and cross-compiler, written in OCaml
By
beckford
I've always found it cool to be in roles where I can help a younger generation learn skills to have a bright future. That role is something I do in a few ways (as a parent, robotics mentor, school board advisor and Sunday school teacher) and I suspect most HN readers share the same role and appreciation. And for developing software skills, it was obvious that both the students and I had to have a productive software environment where we could work together. That theme of experienced/inexperienced engineers working together is the context in which I created `dk` as a scripting tool.
My testing ground has been students with one or two AP CS courses (high school computer science in the US), some of whom interned with me. I had to tackle a few problems:
- The development environment had to be simple to setup and the programming language couldn't be complicated - The recognition that writing small, easily testable units of work (ex. "scripts") has been the only way I've found for very junior programmers to develop a large application - Cheap, locked-down development hardware (ex. school computers with limited RAM and no Administrator privileges) is sometimes used for deployment to cheap hardware targets (ex. hand-me-down Android tablets)
My solution was to write a standalone binary called `dk` that uses scripts as the atom of work, cross-compiles to standalone executables, and downloads the runtimes and sysroots it needs on-demand. It sits roughly in the same space as Python and Go.
`dk` is available for Windows, macOS and Linux/glibc host machines with a growing list of cross-compilation targets. Your `dk` scripts are written in an almost complete subset of OCaml 4: all `dk` scripts are OCaml, but not all OCaml code can run in `dk`. The other differences from conventional OCaml are that `dk` comes with a large library included, and that I treat any feature as buggy if the feature does not work on all supported OS-es.
The above origin of `dk` is admittedly odd (and abbreviated), so I was not expecting that `dk` would now be a general-purpose scripting tool. Yet it is. I can wrap, re-use and organize most of my hand-written software as a set of `dk` scripts.
Fair warning: The cross-compilation support in `dk` has had a recent overhaul and not every bug is closed. The error messages suck (you have to scroll up to see the root cause and resolution) but they will improve. Some progress bars are missing. There are also a few experimental features ... `uv`-style imports and an interactive interpreter are the big ones ... which are purposely under-documented because I am worried about `dk`'s API surface.
But it still works well, and you can see some real applications in the Examples section. I'd love if you could give it a kick in the tires and give `dk` some feedback! The issue list is at <https://github.com/diskuv/dk/issues>.
Comments URL: https://news.ycombinator.com/item?id=44290121
Points: 3
# Comments: 0
You might also wanna read
Malaysia enforces social media ban for children under 16, requiring age verification from platforms
Malaysia has begun enforcing a ban on social media accounts for children under 16, requiring platforms like Facebook, Instagram, TikTok, and
Running Gemma 4 on a 2016 Xeon Server with No GPU: A Technical Walkthrough
The article describes running Gemma 4 (a 25B-parameter Mixture-of-Experts model) on a severely outdated server with a 2016 Intel Xeon E5-262
NVIDIA RTX Spark — Slim Laptops & Small Desktops
Microsoft and NVIDIA announce new Windows PCs accelerated by RTX Spark at GTC
Microsoft and NVIDIA announced a collaboration at NVIDIA GTC to create the world's most powerful and efficient thin-and-light Windows PCs, a
Microsoft unveils Surface Laptop Ultra with NVIDIA RTX Spark for creators and developers
Microsoft announces the Surface Laptop Ultra, a high-end laptop co-engineered with NVIDIA and optimized for RTX Spark. The device is positio
Vera C. Rubin Observatory Set to Discover Millions of Asteroids and Transient Phenomena in Big-Data Astronomy Era
The Vera C. Rubin Observatory in Chile is preparing to begin operations, designed to capture the entire Southern Hemisphere night sky every
