News for hackers. Stuff that matters.
Re:A statically typed scripting language that transpiles to ... by throwaway894345 on Friday March 25, 2022 @10:46AM (#30802789)
This seems neat. I love that there are examples front-and-center on the README page. This is exactly what I want and the first thing I would think to put when demonstrating a new language, but sadly this is rare.

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.

Re:A statically typed scripting language that transpiles to ... by em-bee on Friday March 25, 2022 @11:49AM (#30803602)
I love that there are examples front-and-center on the README page

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.

Re:A statically typed scripting language that transpiles to ... by smoe on Friday March 25, 2022 @04:18PM (#30806636)
Felt the same. Most complete example seems to be the installer for the language which is written in it. This covers some of the things you mentioned

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

https://cotowali.org/

Re:A statically typed scripting language that transpiles to ... by remram on Friday March 25, 2022 @08:15PM (#30808183)
So this 366-line script compiles into 588 lines of shell, 2,229 lines if we count the parts that seem to come from the imported modules. That includes a lot of auto-generated names like `_cotowali_tmp_166` or `first8b04d5e3775d298e78455efc5ca404d5` and replacements for built-in shell functions like `eprintln` or `rm_r`. In fact that script seems to use `eprint`, `eprintln`, `println`, `print`, AND `echo` which seems a little much.

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.

Re:A statically typed scripting language that transpiles to ... by mixedCase on Friday March 25, 2022 @02:21PM (#30805489)
Alright, here's the hot take: The assignment is for any developer without basic knowledge of FP beyond .map and .filter to complete their intermediate-level programming education.

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.

Re:A statically typed scripting language that transpiles to ... by verall on Friday March 25, 2022 @03:12PM (#30806008)
I think it's a super hot take because the real world has demonstrated (over and over again) that a huge portion of professional software developers have no interest in learning functional paradigms just to write some config files.

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".

Re:A statically typed scripting language that transpiles to ... by mixedCase on Friday March 25, 2022 @05:05PM (#30807050)
That'd be fine if it was just config files, but that's not the problem now isn't it?. It's an enormous amount of problem domains that FP handles trivially and is a complete pain to manage imperatively. We've had entire groups of people coming up with ridiculous ideas like replacing relational databases with key-value stores for relational data just because they find SQL "icky" because it fits a mental model they never developed (syntax issues with SQL aside) and it isn't until they're hand rolling data aggregation that they realize the mess they got themselves into.

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.

Re:A statically typed scripting language that transpiles to ... by staticassertion on Friday March 25, 2022 @05:27PM (#30807214)
> (over and over again)

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.

Re:A statically typed scripting language that transpiles to ... by klekticist on Friday March 25, 2022 @04:09PM (#30806556)
I agree with your point here, though imo it's worth drawing a distinction between the FP concepts the language designers / implementors must understand and the FP concepts the language users must understand.

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.

Re:A statically typed scripting language that transpiles to ... by throwaway894345 on Friday March 25, 2022 @11:10PM (#30808936)
I mean, maybe. I’ve dabbled in FP a fair amount, but I was never convinced that it’s categorically better for developing software than imperative programming. Certainly it has its strengths and I enjoy it. But ultimately it doesn’t matter because the reality is that imperative languages dominate the industry, and I doubt that will change for the next decade if only for inertia.
Re:A statically typed scripting language that transpiles to ... by Xavdidtheshadow on Friday March 25, 2022 @03:18PM (#30806066)
Do you have resources to this end that you'd recommend?
Re:A statically typed scripting language that transpiles to ... by mixedCase on Friday March 25, 2022 @04:16PM (#30806609)
The easiest hands-on approach I know of is to go through the Elm tutorial and build a simple CRUD app. The rest should flow from there.

After that, https://fsharpforfunandprofit.com/series/why-use-fsharp/ and pretty much anything made by Scott Wlaschin is very accessible, and to the point.

Re:A statically typed scripting language that transpiles to ... by ModernMech on Friday March 25, 2022 @05:02PM (#30807018)
Missed opportunity: fsharpforfunandfunds
Re:A statically typed scripting language that transpiles to ... by 8n4vidtmkvmk on Saturday March 26, 2022 @02:44AM (#30809805)
so what then is the friendliest functional programming language for those of us with lots of... non-fp experience but very little fp exposure?
Re:A statically typed scripting language that transpiles to ... by catlifeonmars on Saturday March 26, 2022 @01:37PM (#30813707)
The ML family is the most reasonable IMO. Languages such as OCAML and ReasonML feel like they’re designed to solve real world problems rather than adhering to type manipulation pedantry.
Re:A statically typed scripting language that transpiles to ... by xmcqdpt2 on Sunday March 27, 2022 @07:48AM (#30819523)
"Standard" Scala (i.e. without the fancy monadic libraries like cats or zio) and Rust are both mixed paradigm languages with good support for many FP constructs.

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.

Re:A statically typed scripting language that transpiles to ... by tasuki on Saturday March 26, 2022 @03:52AM (#30810080)
Imo, Elm is the friendliest pure functional language. It's a frontend language though.

I'm a backend developer by trade and Elm made me fall in love with frontend development, which I've rather hated before.

Re:A statically typed scripting language that transpiles to ... by sdevonoes on Friday March 25, 2022 @11:21AM (#30803241)
What I miss in the README page is the output of the transpilation.
Re:A statically typed scripting language that transpiles to ... by maggs on Friday March 25, 2022 @03:46PM (#30806358)
I, too, missed that in the README. I was curious enough try it out in a vm. Here's the output for fib.li: https://termbin.com/pagk Or for something more complex, raytracing.sh: https://termbin.com/4rpd

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.

Re:A statically typed scripting language that transpiles to ... by JyB on Friday March 25, 2022 @11:39AM (#30803458)
I guess the output is not really meant to be readable in any way
Re:A statically typed scripting language that transpiles to ... by em-bee on Friday March 25, 2022 @11:45AM (#30803535)
if it transpiles to sh then the output should be an sh script. that should be at least somewhat readable.
Re:A statically typed scripting language that transpiles to ... by xyzzy123 on Friday March 25, 2022 @11:52AM (#30803651)
Yes although it might be readable in the same way that autotools configure scripts are readable -- technically you can, but you probably don't want to, and if you need to then something has gone badly wrong.
Re:A statically typed scripting language that transpiles to ... by xg15 on Friday March 25, 2022 @01:57PM (#30805269)
I mean yes. Things do go wrong, especially with bleeding-edge projects such as this.

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.

Re:A statically typed scripting language that transpiles to ... by em-bee on Friday March 25, 2022 @12:48PM (#30804410)
yeah, that's kind of what i meant. especially if the script has external commands you should be able to at least recognize something.
Re:A statically typed scripting language that transpiles to ... by ketralnis on Friday March 25, 2022 @12:31PM (#30804160)
That's not a given, think typescript compiling to minified javascript. Some compilers like coffeescript do put in some effort to have the output be readable but I wouldn't assert that it should be a goal for everyone
Re:A statically typed scripting language that transpiles to ... by eyelidlessness on Friday March 25, 2022 @01:05PM (#30804638)
> typescript compiling to minified javascript

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).

Re:A statically typed scripting language that transpiles to ... by ketralnis on Friday March 25, 2022 @06:46PM (#30807729)
You caught me, I've never written typescript. I don't think that changes my claim though
Re:A statically typed scripting language that transpiles to ... by eyelidlessness on Friday March 25, 2022 @08:47PM (#30808336)
I think I have varying and stronger feelings about it depending on context. Personally if I were to use this or any compile-to-shell thing, I’d probably prefer it produces unreadable output. I don’t want to ever read bash if I can help it. If I have to, it’s a good sign I’m already beyond my preferred scope for using bash in any way.

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.

Re:A statically typed scripting language that transpiles to ... by Brian_K_White on Friday March 25, 2022 @04:54PM (#30806950)
It's possible to express many common features and functions of other languages in sh fairly well, so it's probably possible for a tool like this to output something not too bad.

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

Re:A statically typed scripting language that transpiles to ... by catlifeonmars on Saturday March 26, 2022 @01:46PM (#30813787)
Also, source maps a la JavaScript.
Re:A statically typed scripting language that transpiles to ... by hnlmorg on Friday March 25, 2022 @11:55AM (#30803690)
I think you can liken this to web assembly. The output might be text but it’s not intended to be human readable.
Re:A statically typed scripting language that transpiles to ... by kazinator on Friday March 25, 2022 @10:53AM (#30802907)
> I'm not sure how I'd use something like this.

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).

Re:A statically typed scripting language that transpiles to ... by soraminazuki on Saturday March 26, 2022 @06:04AM (#30810571)
> making everyone learn its syntax and functional programming idioms probably negates the advantages of using static typing

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.

Re:A statically typed scripting language that transpiles to ... by kirbyfan64sos on Friday March 25, 2022 @12:53PM (#30804479)
You might find Cue interesting: https://cuelang.org/

It's a bit overambitious IMO, but it tries taking a relatively different approach to the problem that I find to be quite interesting.

Re:A statically typed scripting language that transpiles to ... by sidpatil on Friday March 25, 2022 @01:54PM (#30805232)
Parent already mentioned their investigation of CUE.
Re:A statically typed scripting language that transpiles to ... by Willamin on Friday March 25, 2022 @12:15PM (#30803961)
> simple statically typed scripting languages for generating YAML/HCL/etc configs

Do you actually want a statically typed _imperative_ language for generating configs?

Or do you want a sane, statically typed, declarative language for configs?

Re:A statically typed scripting language that transpiles to ... by throwaway894345 on Friday March 25, 2022 @07:29PM (#30807957)
I haven’t seen a sane declarative language. I’m pretty sure what I want is an imperative language, especially since that’s already well-understood by the target audience. I’m open to persuasion, but I gave Cue an honest shot but it seemed to regard reuse as an afterthought at best rather than the main problem to solve (I think reuse was possible, but it wasn’t obvious and it seemed like it was only supported by accident).
Re:A statically typed scripting language that transpiles to ... by lakecresva on Friday March 25, 2022 @04:20PM (#30806659)
The functional stuff in Nickel is really pretty vanilla, and the syntax seems much more inspired by ML than Nix. There's some info in the repo's `RATIONALE.md` that specifically answers "how is this different/better than Dhall/JSonnet/Cue/Starlark".