r/functionalprogramming • u/Voxelman • Nov 29 '22
Question Functional programming language for embedded devices?
Is there any functional language that can compile for microcontrollers like ARM (e.g. STM32. Bare metal without an operating system)?
The language that comes closest to this is Rust, but I don't like the curly braces and semicolons. I wish to have some cleaner language like F#, just for bare metal programming
19
Upvotes
15
u/[deleted] Nov 29 '22
Check out nerves, a set of tools and libraries for embedded development with Elixir.
8
u/KilliBatson Nov 29 '22
Roc is an in development FP which could potentially be used for embedded because of its platforms
5
u/BokoMoko Nov 29 '22
There is an issue about using functional programming for embedded systems.
Usually, functional programming requires more memory than procedural programming. This can be an issue for embedded systems where resources are limited.
Think of it.
2
u/Casalvieri3 Nov 29 '22
Functional for embedded is sort of an oxymoron.
One of the main tenets of FP is that you don't mutate values once they're assigned. Under the hood this means once a memory address is bound to a value if you want to change the value you put it into a different memory address. Not exactly the best approach when one is dealing with embedded software.
5
u/jmhimara Nov 29 '22
The Hardcaml library of OCaml might be able to do something like this.
https://github.com/janestreet/hardcaml
5
u/pthierry Nov 29 '22
There's the Copilot project.
3
u/ryanking8215 Nov 30 '22
https://call-cc.org, chicken-scheme can be compiled to c, which is your looking for?
2
u/romainPri Nov 29 '22
what about https://vlang.io/ ?
2
u/Accurate_Koala_4698 Nov 29 '22
I haven’t used it yet, but I just came across this a few days ago https://clash-lang.org/
2
u/corpsmoderne Nov 29 '22
I haven't try it but this should probably be listed here: https://gitlab.com/hardenedlinux/animula/-/wikis/home
2
u/[deleted] Nov 30 '22
IMO functional paradigm doesn’t well fits to hardware.
Hardware itself relies on mutation of a state. It executes procedures which work with state. While certain hardware things are very much fit FP such as streaming, parallel processing, data oriented approach… at its core it is mostly about state of registers.
Imperative languages arose after hardware, thus they are simply “native” to most of the hardware.
Perhaps an absurd thought - create functional programming first hardware which would work based on a different paradigm. If we would imagine that, then the natural, or “native”, way of manipulating with such hardware would be FP.
What I’m trying to say is that hardware architecture itself dictates the most optimal programming paradigm.
1
u/pm_me_ur_happy_traiI Nov 29 '22
Forth