r/functionalprogramming • u/newgoliath • Oct 10 '24
Question FP language for Unix Scripting?
I'm a Linux admin who wants to get into FP. Any languages out there that are strict FP (single assignment, etc) that will let me easily move around files, start and stop processes, shell out, etc.?
30
Upvotes
31
u/Rschmukler Oct 10 '24
If types aren’t a requirement for you, I’ll recommend Clojure via Babashka. https://babashka.org
10
u/11fdriver Oct 11 '24 edited Oct 11 '24
Erlang is not an ideal scripting language, with relatively weak string manipulation ootb, but it excels at some tasks. Notably escript let's you run a script via shebang, and in recent versions compiles the script by default before running.
Elixir also permits a shebang line and has better tooling for scripts imo. You can also use Mix to compile a script into an escript file if you prefer that workflow, or just run it straight.
D is a nice language that allows a shebang line and has some great FP facilities, though it isn't strict fp. The script is compiled and cached so it runs quickly after the first time.
Guile Scheme is well-suited to both FP and scripting, as it's intended to be an embeddable scripting language for other programs. It stands very well on it's own and supports a shebang as a comment unlike many other lisps. It has some interesting features that simplify a lot of common scripting tasks.
Julia is supposed to be quite nice to script in, also, but I haven't tried it much.
Personally I can't recommend babashka enough. It's what I reach for in my personal projects and a couple of collaborative ones too. It's a very well-thought out tool that runs quickly from a cold start and comes with many batteries included.
6
u/Voxelman Oct 11 '24
F# maybe. Or Nushell
5
u/aaaaargZombies Oct 10 '24
https://www.gnu.org/software/guile/manual/guile.html maybe
4
u/miyakohouou Oct 11 '24
There's Turtle for shell scripting with Haskell. I haven't used it, but I often use Haskell for writing quick scripts and it works well.
6
u/eosfer Oct 10 '24
scala with scala-cli https://scala-cli.virtuslab.org/scripting/ ?
3
u/Classic-Try2484 Oct 10 '24
Common Lisp can probably do the job
3
u/WhiskyStandard Oct 11 '24
I’ve always been intrigued by the Scheme Shell (scsh), admittedly mostly because of the legendary Acknowledgement section in its manual. Never seen it used in real life, but there have been a number of times when I’ve been frustrated with bash almost to the point of trying it.
3
u/bas_kuch_nhibro Oct 11 '24
Nix shell ? Or nushell?
3
u/Asleep-Dress-3578 Oct 11 '24
Common Lisp & Roswell? https://youtu.be/QHwghMNKVtg?si=unmEcqHnbyGFRhOT
Or just use Hy and enjoy the Python ecosystem?
3
u/KyleG Oct 11 '24
Look at the history of this sub the last week. Someone shared Hell, a scripting language familiar to Haskell writers
5
u/Arshiaa001 Oct 11 '24
F# + fsi is a good option if you're not allergic to things made originally by MS.
4
u/Delta-9- Oct 10 '24
It's not strictly FP, and it's also not complete, but NuShell has enough closures to make a Haskell programmer blush and, like most shell languages, encourages point-free style. At the same time, it borrows from PowerShell and others the idea of structured data flowing through pipelines (rather than plain text) but favors tabular data over object models.
I used it a bit a year ago for a small data slicing side project and rather enjoyed working with it. It was far from a complete experience at the time (basic things like suspending a program with
^Zhadn't been implemented yet—the devs were more excited about integrating Arrows' dataframes right into the shell), but it did at least have the utilities you need for basic administration and it can run and parse posix shell utilities' output so you can integrate them into a NuShell pipeline easily. And it was fun to write. I'll probably give it another try one of these days...2
u/bilus Oct 11 '24
nix? :)
2
u/zzantares Oct 11 '24
Just today a coworker shared https://chrisdone.github.io/hell/examples/ to use haskell for scripting.
2
u/raka_boy Oct 12 '24
Uiua
2
u/flatmap_fplamda Oct 12 '24
You can use Scala-cli and start getting into scripting
2
u/ops-man Oct 14 '24
Use Haskell and ghci. Fully FP and the system libraries are acceptable.
2
u/Tbetcha Oct 16 '24
F# is a good choice, both as a way to get into FP and for scripting. It’s not super strict like some pure FP languages which makes it good to learn for beginners. It’s terse and the syntax isn’t complicated to learn. The REPL also allows you to execute chunks of code without having to run the whole program which is great for scripting.
2
u/_memark_ Oct 27 '24 edited Oct 27 '24
May I ask what your motivation is for wanting to use FP here? I adore FP myself, it's not that, but I think that most unix scripting tasks is all (only) about side effects. I mean, if you do everything inside a "do" block anyway, what value does the FP bring?
2
u/EdgyYukino Oct 10 '24
There is hell: https://chrisdone.github.io/hell/ But I am afraid that it isn't designed for interactive usage.
2
u/thelockz Oct 10 '24
Hell comes to mind https://github.com/chrisdone/hell
2
u/MrVegetable Oct 10 '24
Possibly https://adam-mcdaniel.github.io/dune-website/