r/functionalprogramming • u/Voxelman • Feb 15 '24
Question Scripting language like Python, bur with the feeling if Rust
Rust is a great language, but sometimes I wish to have something more like Python, but with a more "Rusty" feeling.
With "Rusty" feeling I mean project management with cargo, Error Handling with Result/Option, pattern matching, strong static typing with type inference, immutability by default and so on.
This means, I'm searching for a functional programming language. My problem is, that all functional languages I found until now compile to something intermediate like Beam, JVM, .NET, JS or build binaries like Haskell.
What I'm looking for is a scripting language like Python. Just an interpreter, that runs a script, but with the "if it compiles, it runs" experience of Rust. And yes, I know that compile time type checking and script interpreter are different kind of shoes, but who knows...
Any idea?
Thanks for all the comments. A lot of good suggestions, but I decided to go with F#. I think it comes closest to Python. It runs on Linux and Windows, can run in a Jupyter like notebook and has a nice syntax. I have some (rudimentary) experience and the book "domain driven design made functional" from Scott Wlaschin, which I really like. It is well documented and you can find lots of books, tutorials and videos. Languages like Mojo lack documentation.
It is not as "Rusty" as I would like, but close enough. So if someone is searching for an alternative to Python, try F#
14
u/tifridhs-dottir Feb 15 '24
I know what you mean.
I'm still searching, and there are definitely a few that stand out recently (Erg, maybe Mojo... And in general languages with a core written in rust lol)
But tbh I've been the most productive lately using Coconut . It's honestly phenomenal and very well integrated and thought out w.r.t existing python tooling.
And if you want strong runtime types, it's fully compatible with beartype, as far as my testing can find. I love coconut and regularly miss it when I go back to vanilla python.
6
u/fasttalkerslowwalker Feb 15 '24
F# or gleam
5
u/Ja-Chiro Feb 15 '24
F# fsx scripts
5
u/dogweather Feb 16 '24 edited Feb 16 '24
I'm getting about 95% of your wish list using Python with these mainstream add-ons:
flipandcurry. I occasionally create Elixir-like pipelines like I blog about here.Literal) in my code. Blog: https://dogweather.dev/2024/02/04/a-data-driven-app-without-the-database/Don't get me wrong, it's still Python, and so still kinda sucks. IMO mostly due to the baggage that comes with age. Also its schizophrenic attitude towards functional programming.
But I did just have a great refactoring experience due to the powerful type hint system.
And the ability to use either Jupyter Notebooks to test code, or several different REPLs is great.
Finally, like I mentioned before, each of these little tools and add-ons are very well supported with huge user bases.
FWIW, I started down the path of my current app and client work in Python because it's supported well by OpenAI. This is all AI client stuff. If that hadn't been the case, I'd also be looking into a Rust-lite.
4
u/aaaaargZombies Feb 15 '24
gleamsounds like a good option to me,roclooks promising but even less mature. I have used elm-posix which gives you access to the very mature and stable elm ecosystem... but it's built around a lot of web use-cases. Very nice to work with the core data structures and libraries though.3
u/met0xff Feb 17 '24
I hope for Mojo
4
u/Afrotom Feb 15 '24
I don't know if this is what you're looking, but Mojo is basically rust with python syntax.
What I mean by that is it has a concept of ownership and lifetimes, is strongly typed etc. but also leaning more into use for machine learning so simd OTB.
I haven't really used it to talk about it in length but there's a video here about it.
37
u/lightmatter501 Feb 15 '24
Haskell’s GHC is very happy to be an interpreter.
23
u/Puzzleheaded-Lab-635 Feb 15 '24
OCaml? but not dynamic.
Elixir, can be run like a scripts just name any `.ex` file to `.exs`
https://underjord.io/scripting-with-elixir.html
16
u/gplgang Feb 15 '24
F# has scripting with FSI
9
u/_consoli Feb 15 '24
I've never used it before, but Gluon may be interesting for you.
It has that Rusty flavor (and it's written in Rust), but also has a REPL and functional features & patterns (std with monads, applicatives, etc)
but it's a WIP project and idk the real state of it.
gluon-lang.org playground
13
u/delfV Feb 15 '24
Neither of them are (pure) functional languages so are you sure you're on right sub? But Nim is similar to both Python and Rust afaik, but I don't know much about it
6
u/davesmith00000 Feb 15 '24
By some coincidence, I just wrote about this - kinda. It is unashamedly aimed at Scala devs, but Scala 3 is ...like Python but with all the functional goodness.
https://xebia.com/blog/better-shell-scripting-with-scala-cli/
Re-reading your post, perhaps it isn't quite what you're after, but thought I'd mention that you can build native binaries this way too. So although it's Scala, you can ditch the JVM bit.
6
u/Il_totore Feb 15 '24
Looks like Scala to me. It has an indentation-based syntax since Scala 3, has a pythonic ecosystem (li haoyi) and Scala CLI is a great tool to make scripts. Technically not "only an interpteter" but from UX PoV it is the same (a single command to run the script) minus time before execution (can take a second to start due to compilation).
2
u/whatsnewintech Feb 15 '24
A practical choice would be Deno. Performant runtime with nice sandboxing, thriving, gradually-typed, functional-friendly language (Typescript).
2
u/springy Feb 15 '24
Mojo is a modernised, and massively faster, version of Python. It includes a lot of Rust inspiration, such as the ownership/borrowing memory model.
5
u/sideEffffECt Feb 15 '24 edited Feb 15 '24
Give Scala with scala-cli a try
https://scala-cli.virtuslab.org/docs/guides/scripting/scripts#self-executable-scala-script
This may be exactly what you're looking for.
Concrete example: https://xebia.com/blog/better-shell-scripting-with-scala-cli/
5
u/dnlmrtnz Feb 15 '24
Definitely sounds like F# is what you are looking for. You can use it for building scripts with FAKE (is read of make), running stand alone fsx scripts, interactive repl with fsi, full blown backend services, and frontend applications with fable.
5
u/SoftEngin33r Feb 15 '24
Roc lang ?
4
u/accidentally_myself Feb 15 '24
Scala. Quite python-esque. No need to compile, just run. There's also https://ammonite.io/ if you want a 'shell'.
4
u/akirakom Feb 16 '24
Not really a scripting language, but Koka is a functional language with effects, runs as fast as C once compiled, and has a concise syntax like Python: https://koka-lang.github.io/koka/doc/book.html
1
u/Dirty_Rapscallion Aug 16 '24
Maybe try Gleam?
3
u/PriorTrick Feb 15 '24
Ocaml 🫡
3
u/mchwds Feb 15 '24
Seems like Nim is what you’re looking for.
3
u/JasonDoege Feb 15 '24
Raku is my favorite scripting language to pair with Rust.
3
u/2001zhaozhao Feb 15 '24
Kotlin scripting is close.
"If it compiles, it works" is certainly true here.
It's not really a true scripting language though, but they've made it pretty close to feeling like one.
If you want something more functional I'd be curious if Scala has something similar.
3
u/thx1138a Feb 15 '24
I don’t know what exactly you are wanting from your scripts, but for many tasks VS Code plus Polyglot Notebooks plus F# is a brilliant combination.
3
u/Economy_Bedroom3902 Feb 15 '24
What exactly is it about an interpreted language that you need? I can't see a good reason from your post why you can't just write an alias to compile and run Rust as a single command.
3
u/adwolesi Feb 15 '24
Haskell Stack script interpreter: https://docs.haskellstack.org/en/stable/scripts/
3
u/pthierry Feb 15 '24
I currently use Nix to create self-contained Haskell files I can make executable. I use Nix so they can use dependencies:
3
u/davesnx Feb 15 '24
it seems like you're looking for OCaml 🧐
3
u/4runninglife Feb 16 '24
Try Nim, best language i ever used.
-Python Like Syntax
-C speed
-interoperable with C code
-Compiles to C, C++ and javascript
-Creates small binaries
I could go on and on.
3
u/[deleted] Feb 16 '24
Ocaml or Haskell
3
u/SeminalTorpedo Feb 16 '24
Scala can be run as a script without jvm. There are a lot of reasons I believe scala is the most criminally underused language, and this is one.
3
u/entropyvsenergy Feb 16 '24
Julia is a functional programming language with JIT compilation, multiple dispatch, and robust type checking. It might suit your needs.
3
u/drinkcoffeeandcode Feb 16 '24
ITT: name your favorite and say its exactly what op needs
Have you considered Lisp?
3
u/BokoMoko Feb 16 '24
Mojo
3
u/Oryan_physics Feb 17 '24
My first thought is Julia. It's whole schtick is "writes like python but runs like C". I use it for large scale physics simulation. Its really easy to pick up the syntax and it doesn't sacrifice speed for it.
3
u/winsome28 Feb 17 '24
Not exactly what you're asking for, but consider Nim! https://youtu.be/48CsjEFzyXQ
3
u/yellomango Feb 19 '24
Golang!
2
u/cthutu Feb 16 '24
This is not an interpreter but it compiles fast. There's a language that is inspired by Rust, looks like Python and actually interops with Python code.
It's called Mojo. It's written by Chris Lattner and performs faster than Rust.
2
u/mathartist Feb 19 '24
I haven’t seen nushell suggested yet. It’s sort of a Rust-inspired take on shell scripting, and it’s quite well done.
2
u/[deleted] Feb 15 '24
Other than Haskell, lean has AI pattern-matching with copliot, and overall well-developed supports.
2
u/mkubasz Feb 21 '24
Golang, bun shell (ts with magic), Mojo
-3
u/D_4rch4ng3l Feb 15 '24
Interpreted (or scripted) languages do not compile. That is their whole deal.
Compilation is exactly the process of generating the optimised binary from the source code.
How can you have something which "runs as a script in interpreter" (which means no compiling) but also "if it compiles, it runs" (but you are not compiling at all).
Compliation has no direct relation with type checking. Although most typed langauges are also compiled languages.