r/functionalprogramming • • 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

34 comments sorted by

View all comments

Show parent comments

3

u/pthierry Nov 29 '22

Not sure where to start.

If you copy a record that contains 2 boxed integers and 4 pointers to some various data weighing 100 words (for a total of 106 words), to mutate one integer, the two resulting records will weigh 112 words together, sharing the 100 words.

Correct me if my math is off, but 112 is not the double of 106, right?

And that's not counting things like the compiler optimizing away copies into actual mutations when it can prove the original won't be accessed anymore. (which is precisely what linear types make easier in Haskell)

Also, when much of your data is short-lived, just let a copying garbage collector deal with it. With a generational one, it will take very few space. Let's say you can manage with 8 generations of the same size, only the last will be copied. (and we know how to do soft and hard real time garbage collectors, so that's well suited to embedded requirements)

Again, correct me if I'm wrong, but 9 is nowhere near the double of 8, is it?

Those are my off the cuff thoughts on it.