19

I was discussing F# and Functional Programming with a friend last night and he brought up an interesting question to me. How would you do embedded software in functional? I mean this seems like a fairly natural fit in terms of stateless code but embedded also entails being very frugal with memory and I'm not sure of the story for functional in that regard.

Any suggestions about languages or packages for embedded with functional?

Onorio Catenacci
  • 2,937
  • 3
  • 26
  • 37
  • This link could help you ftp://ftp.cs.york.ac.uk/pub/malcolm/thesis.html. Download the postscript file and read it. – Ubermensch Mar 02 '12 at 14:07
  • @Ubermensch thanks but I'm getting an error when I try to access that link. – Onorio Catenacci Mar 02 '12 at 14:27
  • 3
    Please take a look at this SO [question](http://stackoverflow.com/questions/4418617/are-there-any-special-challenges-for-functional-programming-in-an-embedded-envir). It appears to be very closely realted to what you've asked. And this [page](http://blog.sw17ch.com/wordpress/?p=111) dealing with programming the Arduino with Haskell.Atom – Bhargav Mar 02 '12 at 15:28
  • @OnorioCatenacci This link is the actual postscript file ftp://ftp.cs.york.ac.uk/pub/malcolm/thesis.ps.Z – Ubermensch Mar 03 '12 at 04:08
  • 1
    You may also be interested in reading [Using Haskell for sizable real-time systems: how (if?)?](http://stackoverflow.com/q/1263711/42473) – Mark Booth Mar 05 '12 at 12:16

2 Answers2

3

Forth is an excellent choice for embedded systems programming. Being a stack language, it can be analysed in terms of function composition (concatenative programming). I see no reason why such a language with more functional aspects could not also be implemented efficiently, but as yet no such thing (to my knowledge) exists.

Jon Purdy
  • 20,437
  • 7
  • 63
  • 95
  • 1
    Concatenative programming is a very different paradigm to Functional programming, but there is a functional forth ([funforth](http://forthfreak.net/index.cgi?FunForth)) which implements some simplified aspects of the [Haskell](http://en.wikipedia.org/wiki/Haskell_%28programming_language%29) functional language language. – Mark Booth Mar 05 '12 at 12:14
  • @MarkBooth: Not so different; concatenative programming (pretty much by definition) makes heavy use of higher-order combinators, and many functional concepts translate directly into concatenative code. – Jon Purdy Mar 06 '12 at 19:09
3

One option is Erlang. From the wikipedia page:

Erlang is a general-purpose concurrent, garbage-collected programming language and runtime system. The sequential subset of Erlang is a functional language, with strict evaluation, single assignment, and dynamic typing. For concurrency it follows the Actor model. It was designed by Ericsson to support distributed, fault-tolerant, soft-real-time, non-stop applications. It supports hot swapping, so that code can be changed without stopping a system.

While threads are considered to be a complicated and error-prone topic in most languages, Erlang provides language-level features for creating and managing processes with the aim of simplifying concurrent programming. Though all concurrency is explicit in Erlang, processes communicate using message passing instead of shared variables, which removes the need for locks.

The first version was developed by Joe Armstrong in 1986.2 It was originally a proprietary language within Ericsson, but was released as open source in 1998.

Mark Booth
  • 14,214
  • 3
  • 40
  • 79
  • Although Erlang may be used in systems that require low-level programming it seems the low-level parts are typically not done in Erlang but in C ([Erlang FAQ](https://www.erlang.org/faq/introduction.html), "What sort of problems is Erlang not particularly suitable for?"). – Stefan Schmidt May 12 '22 at 14:15