A statically typed scripting language that transpiles to Posix sh
github.com
github.com
I'm not sure how I'd use something like this, but I've often found myself wanting simple statically typed scripting languages for generating YAML/HCL/etc configs. Dhall seems close, but config is something that every engineer has to touch and the burden of making everyone learn its syntax and functional programming idioms probably negates the advantages of using static typing. I've also looked into CUE, but it seems like it's largely neglecting the problem that I'm trying to solve DRY configs in favor of some problem I didn't know I had (unifying a bunch of layers of mostly-static configs?). This seems even worse than Dhall with respect to burden:reward ratio. I haven't yet checked out Nickel (the statically typed Nix language)--would be curious to hear from those who have.
EDIT: just skimmed Nickel. It seems like it's trying to hew closely to Nix syntax and functional programming conventions, which suggests it probably shares many of the same problems as Dhall. Too bad. It seems like no one understands the assignment.
It seems that you could use this to program embedded systems that have a shell, yet which don't support any other usable language (due to flash space concerns, product management approval or whatever).
You'll have to look at that output if you want to debug things, understand error messages.
As such, I'd absolutely see it as a quality measure for a transpiler how readable the code it produces is.
This is an odd example. TypeScript compiles to readable JavaScript for nearly everything except the odd runtime behavior (eg enums) and “downleveling”, which is increasingly unnecessary. Minification is still a separate step AFAIK (if you’re using tsc; obviously ESBuild and SWC are another story, as will be Bun).
Whereas if I’m compiling TypeScript/CoffeeScript/anything to JS, it’s pretty likely I already have JS as a built in constraint and I probably want to be able to read the output so I can debug it.
But even so, I would never expect any transpilation output to be more than technically readable.
The part with the high level meaning is the part the human wrote. That's the entire point of any language.
The output can not be considered source, regardless that it's possible to also write source in that same syntax.
The only reason to even bother with transpiling instead of just requiring the necessary interpreter, is to ship something that the target already supports. It's very very little different than shipping a binary.
The differences are just that a .sh is at least possible to read and hack vs not-possible. Not convenient or good, merely possible vs not-possible. And a .sh is more portable than a binary in that it doesn't care what the cpu or os is.
If you want anything more high level meaningful instead of some 90's web page generator html output, you have to write that yourself. An automated tool cannot reverse engineer some code into an elegant expression of the original intent of that code. In that way a compiler or transpiler is not much different from a decompiler.
Though, I admit there is room for levels. I don't know just how crude this tool's output is, but I know there is a range of what's possible, it does't have to be
I was mostly wondering how/if it does any type checks for function input; it does not. Also raytracing.sh unfortunately fails to run on my system as it is.
except that those examples are to simple. for something that transpiles to sh i would like to use it to write better shell scripts. so i'd like to see examples that resemble actual shell scripts in that they call lots of external commands, do file operations, terminal interaction and other things commonly done with sh.
https://github.com/cotowali/konryu/blob/main/konryu.li
and the generated shell script
https://raw.githubusercontent.com/cotowali/konryu/dist/konry...
There is also the website, heavily under construction, but has some more documentation on the language than the readme
It would have been nice to see something more transparent, e.g. a type-checked extension to shell, like TypeScript is for JavaScript. Something to make it easier to write correct shell scripts, but would generate understandable, editable shell scripts.
Do you actually want a statically typed _imperative_ language for generating configs?
Or do you want a sane, statically typed, declarative language for configs?
It's a bit overambitious IMO, but it tries taking a relatively different approach to the problem that I find to be quite interesting.
All problem domains that involve declarative programming, such as configuration (Terraform, Kubernetes, Nix, many build systems), dynamic HTML, relational databases, and pretty much anything that is manipulating data in a pipeline fits functional programming like a glove and is hard to get right in a strictly traditionally imperative fashion. As an industry we should stop pretending FP isn't a necessary part of a professional programmer's education and that we can solve the problem by coming up with the umpteenth "we promise it's not FP" abstraction with its own take on fooling developers into writing functional code through an imperative-looking layer full of foot guns that subtly break imperative developer expectations, like React.
Just like a huge portion of professional software developers have no interest in learning RTL or digital logic just to program an FPGA.
HLS is a massively complex system to solve this problem. People will also build massively complex systems to solve the problem of "No FP here, please".
Ideally languages prevent bug classes like null deref, use after free while still being familiar enough for most programmers to use.
It's analogous to the spectrum of SQL knowledge folks have. For instance knowing what a group by does vs how a group by reshuffles data on a single node / across nodes. Ideally the language design hides the hard details.
A very tall order admittedly.
Which is why I stand by what I said: this knowledge is not optional, and engineers not willing to learn them are going to be stuck with sub-optimal tools, dragging the whole industry down with them. While I can't be confident this is the definitive solution, I believe that the best way to move forward is to start treating basic FP (purity, data transformation pipelines, immutability, favoring data structures over code) as a baseline that everyone needs to know to work as a developer, and stop treating it as if it is on a superior level of difficulty compared to learning whatever bullshit combination of half-templated server side rendering, 4D DOMs and incantations needed to upgrade Webpack we need to know to be "up to speed" nowadays.
Eh. I'm not saying one way or the other that FP is good or bad, but the software industry is incredibly young and changes a lot. Even in a relatively short period - 10 years, let's say - things are pretty difference. 20 years, still a short time, and things are radically different.
And on top of that, it is still the case that a lot of stuff takes a long time to get adopted. It's hard to build and popularize a programming language, regardless of how good or bad that language is, because they tend to lack interoperability with other languages if they're very different, which is usually a requirement if they want to be considered worth looking at.
So I'd just as easily buy that people haven't used a lot of FP due to inertia, a lack of the right external inventives, etc, and not by any virtue of the paradigm.
After that, https://fsharpforfunandprofit.com/series/why-use-fsharp/ and pretty much anything made by Scott Wlaschin is very accessible, and to the point.
I'm a backend developer by trade and Elm made me fall in love with frontend development, which I've rather hated before.
In practice you can write imperative code using either of them but the focus on immutable data structures, and (in Rust more than Scala) functional error handling means that many manipulations are easier to do with FP constructs, so they appear quite naturally (Option, Result/Try, iterator maps etc.)
As a bonus IME they are very similar in many respects so experience in one translates well to the other.
I think this is an over-exaggeration of the complexity involved because Dhall/Nickel/Nix are just JSON with variables and functions. If you're familiar with JSON and any general purpose programming language, say Python, you can learn the aforementioned languages in less than an hour.
> Too bad. It seems like no one understands the assignment.
You mean all those language designers for static configuration languages have no idea what they're doing? I think there's a better explanation. For complex configurations that warrant the kind of high level configuration languages we're talking about, declarative syntax seems to a better fit. Tracking mutation and state for large scale configuration would put the burden on everyone, beginners and experts alike.
Otherwise, fun project! I could see this actually being useful in some niche cases, e.g. generating scripts that need to work on some exotic architecture that has a POSIX Sh implementation.
It might also be useful for writing interactive shell "plugins" that set up things like a fancy PS1 prompt.
[0]: https://github.com/vlang/v/issues?q=is%3Aissue+is%3Aopen+lab...
The documentation and modules are truthful. What they have claimed to set out to do, is what they are doing and where they are going.
I follow it, and love their ambition...but there are a ton of open issues that convince me it's not even alpha quality yet. If anyone has experience otherwise, would love to hear.
POSIX shell is a good compilation target if you want to write a non-trivial build system, but be able to run it on some old or otherwise challenging systems.
1: To remove bashisms/kshisms/zshisms to create output that works on ash/dash/busybox/xenix/sun/... In which case, the more useful source language is bash or ksh etc, not a new invented one.
2: To generate a portable output like above from a better language than any *sh (*). In which case the source language should be something already common like python or perl or ruby etc (even if just a subset).
In either of those two use cases, I don't think it makes a great deal of sense to make a new language, and especially not to write the compiler for it in V of all things.
That relegates the whole project to being just a curiosity or a purely academic excercise.
(*) I use every trick bash and ksh offer, so I know it's possible to do all kinds of stuff in some *sh's, but a lot of the features in them are encoded into practically inscrutable special syntax and rules and tricks, where more purpose built programming languages make all the features more explicit and spelled out -> readable. bash is a powerful enough language, but not a readable one, except for rairly stupid scripts that either don't do much, or do everything the hard way.
What Andy Chu has been doing with Oil Shell is promising in this respect. It supports optional type annotations. Cf. https://www.oilshell.org/blog/2021/01/why-a-new-shell.html
I think I was insufficiently critical in a misguided intention to be nice. Let me correct that a little :)
If the need is great enough for a DSL, then the need is great enough for python or c or any of 100 other fully fledged universally available languages, and either require it's interpreter or ship a binary.
However annoying it may be to require a ruby interpreter or something, there is essentially no case where the most sensible answer is this "Vala-for-sh".
It's the worst of all worlds. Taking the whole life cycle into account, it's not saner or portable or versatile, it reduces all of those.
A really cool enhancement to this would be if the compiler could target a polyglot script that is both Shell and Batch. For example: https://stackoverflow.com/a/17623721
Then you'd get a single script that would automatically be portable and executable on pretty much every conceivable platform.
Also seeing quick, readable examples right on the github landing page is such a small but wonderful thing.
#!/usr/bin/lic run
Not really that big of a deal, I just like tracking command line apps naming because it is an interesting exercise of being short, intuitive, and unique. When you decide a single letter is your name, surely you are going to run into this.
1. https://github.com/zakuro9715/z 2. https://github.com/skywind3000/z.lua 3. https://github.com/ajeetdsouza/zoxide 4. https://github.com/rupa/z
I feel that this seems like a good idea on paper, and a bad idea in the wild.
Last time I looked into shell syntax and such, I found out that most shells don't. They vary so greatly that very large context-free grammars have to be used to cover most of their context-sensitive rules. I don't think being POSIX compliant changes that.
I suspect that if this got popular usage, the bugs would be quite numerous.
I guess I should look into how this is actually compiled to sh. I agree the README would benefit from adding some examples of this.
nice
+ Nu Shell
+ NGS
+ Powershell
+ Oil Shell
+ Elvish
+ Murex (which is one I'd written)
Not to mention all the LISP, Python, and other such high level language REPLs come shells.But they solve a different problem. This seems to be more like what Typescript is to Javascript: a alternative "safer" language where your end point is limited to supporting a different language. So you need to compile down to a known portable base language.
Going to give this a fairly through once-over because I think Posix sh is an under-appreciated transpilation target.