r/functionalprogramming • u/Voxelman • Mar 03 '24
Question Which functional language for Raspberry Pi?
I want to start a project that should also run on a Raspberry Pi (4 or larger).
My first choice was F#, but after a little research I'm a bit concerned about the memory usage. At least at the language benchmark game the dotnet solutions use more RAM than other languages, even Python need less.
The F# programs need about 10x of RAM compared to Python. Even C# needs more.
I know it's a bit difficult to compare because Python programs are only running on one core, but the difference between C# and F# is still significant. Is it just the special use case or do F# programs need significantly more RAM in general?
Haskell and Ocaml perform much better, but the ARM platform support seems to be not really mature (correct me if I'm wrong).
Is there any funktional language (from the ML family) that can be used on a Raspberry Pi? I need something that is significantly more performance then Python. If not, the next best option would be Rust.
13
u/damnNamesAreTaken Mar 03 '24
https://elixirschool.com/en/lessons/misc/nerves it you're worried about memory constraints?
3
u/msvankyle Mar 03 '24
F# on .NET core should run fine.
2
u/MaxwellzDaemon Mar 04 '24
It's not from the ML family but the functional language J runs on the Pi.
17
u/XDracam Mar 03 '24
A pi can handle anything. Pick whatever you like. If you actually run Into performance constraints, you can always optimize.
I have a pi 3 running a bloated Scala server, including DB and backups and everything. It's been running for years without any issue or required reboot.
8
u/epfahl Mar 03 '24
Elixir (with nerves) is an ideal choice. Really easy to get started, and very sustainable
5
u/[deleted] Mar 03 '24
except if you're having extreme payloads, everything will be fine on any language. Don't optimize prematurely.
5
u/ABrainlessDeveloper Mar 04 '24 edited Mar 04 '24
ghc haskell has tier-1 support on aarch64: https://gitlab.haskell.org/ghc/ghc/-/wikis/platforms/. And it’s been a while since ncg for that platform landed, so I you shouldn’t have any issues running the compiled binary.
My suggestion would be to use nix instead of ghcup in case you struggle with the dependencies.
4
u/fridofrido Mar 03 '24
I haven't actually tried it on RPi, but since apple introduced the arm macs (which are very popular among developers) arm64 support got much better. I have no serious issues using Haskell on an arm mac (and it's native arm, not going through rosetta).
So I image it should work fine on RPi too. Though it will be probably much slower to compile, and you could run into memory limitations when compiling. But you could develop on a more powerful machine and only check the RPi version time to time.
7
u/FalseRegister Mar 03 '24
You could go with Scala and Scala Native
3
u/james_pic Mar 03 '24
Garbage collected runtimes, such as the .Net CLR that runs F#, typically have configurable memory usage, but by default will generally use a significant fraction of available memory, because (at least up at a point) having more memory available allows garbage collection to be more efficient.
So whilst memory usage might be high, it shouldn't attempt to use more than is available unless it needs to.
Also note that Raspberry Pi 4 can have up to 8GB of RAM. 8GB is a number where, if your application is using most of the RAM, then it's most likely application-specific data that's using most of it, rather than anything language runtime related. Even at 1GB, the way your program uses memory is going to matter more than your choice of language runtime in most cases.
3
u/pIakoIb Mar 04 '24
I ran Haskell on Raspberry Pi 2(?) about 8 years ago and it worked without issues. I don't think you'll run into problems using it today.
3
u/Apprehensive_Pea_725 Mar 04 '24
If you don't mind the jvm slow start you can go with Scala, and get GPIO support from java libs.
2
u/mnbkp Mar 03 '24
I don't think there's reason to worry this much about memory usage on a Pi 4 of all things, but if that's what you want, try OCaml.
If you really want to optimize for memory usage (which to be clear: I don't think is needed here), you should maybe consider going with Rust, even if it's not actually functional.
2
u/[deleted] Mar 04 '24
https://jank-lang.org/
2
u/jecxjo Mar 06 '24
Elixir/Erlang or Scala would be the least resource intensive on development. Deployment they all would be fine.
2
u/bishtap Mar 04 '24
I know C# isn't a functional language but you don't need huge resources to run it likewise then F#.. If you aren't using the visual studio IDE. For example you can run a C# program with CSC.EXE And maybe it's similar with F# There might be an F# raspberry pi version to run F# from command line.
4
u/veryusedrname Mar 03 '24
If you think about F# then Rust should be a good choice I think. There are a lot of similarities and Rust has excellent support for Raspberry Pi.
2
u/Herku Mar 03 '24
PureScript on Node.js could be an option. The newer versions of the Raspberry Pi can be equipped with multiple GB of RAM, which should be more than enough to handle hundreds of requests.
What is your use case?
1
u/RedEyed__ Mar 03 '24 edited Mar 03 '24
I'm pythonista, but on the other hand, I love F# syntax (never professionally used it). I know nothing about Haskel, and it looks exotic and not practical at my opinion, sorry Haskell guys, just opinion.
I would choose F# because of great functional support and it has all benefits of dotnet ecosystem. Python is not so great for FP as F# , however, you can achieve similar F# functionality with expression library https://github.com/dbrattli/Expression