Embedded Functional Programming Using Haskell

June 17, 2011
Haskell is one of the most popular functional programming languages but it has not found much use in the embedded space.
That is not likely to change in the near future but there are reasons for considering other languages like Haskell for embedded projects
including the possiblity for proving a program does what it is supposed to. This is easier with functional languages than ones like C.

C remains the language of choice for most embedded developers with C++ close behind. Java is in the mix along with other programming languages but functional programming languages show up in very few embedded discussions. Languages like SCALA (see If Your Programming Language Doesn't Work, Give Scala A Try) that are built on Java virtual machines are more likely to be chosen for new projects than functional programming languages like Haskell. Still, there are reasons why you might want to learn more about the possibility.

Haskell is one of the most popular functional programming languages but it has not found much use in the embedded space. That is not likely to change in the near future but there are reasons for considering other languages like Haskell for embedded projects including the possibility for proving a program does what it is supposed to. This is easier with functional languages than ones like C.

I've only dabbled in Haskell so far. It is easy to do but it is definitely a lot different than C or C++. I've done a bit of work with various Lisp dialects including Scheme. If have a JVM handy but you haven't looked at Kawa Scheme you might want to. It provides the flexibility of Scheme with running on a Java platform with access to all the Java services.

But I digress. One reason for mentioning Lisp is that Lisp is one of the oldest programming languages in general use. It is also used in production systems although most people don't talk about it. For example, AutoCAD uses Lisp and they even have a Visual Lisp.

Lisp has been used in embedded applications but most are not discussed. For that matter, even Lisp use in web services is often something not discussed because the edge it gives developers. It is often that secret sauce.

Anyway, there is some work being done with Haskell in embedded environments. One platform is Atom a Haskell DSL by Tom Hawkins. Applications can even runs on the tiny Arduino platform (see Atom & Arduino :: Some Hacking). In general, a platform that would run Java could handle Haskell. Haskell also requires garbage collection like Java.

The most popular tool for Haskell is the Glasgow Haskell Compiler (GHC). It runs on Windows, Mac, Linux, most varieties of Unix. It can generate native code or it can use LLVM as a back-end. GHC can also generate C code as an intermediate target for porting to new platforms. This could also be used for embedded applications. Haskell also supports an interactive environment that uses compiled bytecode.

I won't go into what Haskell programs look like. That would take quite a bit of space that I don't have here. Besides, I am just a newbie with Haskell. It has a number of features that are not found in most programming languages like lazy evaluation. This is essentially computation on demand. Also, a variable can only be set once.One advantage that Haskell has is its type system. Embedded programmers would like this because it means that many runtime type checks go away since types are known at compile time.

Just in case you don't think Haskell is being used for anything but academics then check out the Commercial Users of Functional Programming site. They have an annual conference as well. By the way, if you are looking for Haskell programmers you might want to check at Microsoft.

Time to try some more Haskell programming. I'll let you know what I discover.

Sponsored Recommendations

Highly Integrated 20A Digital Power Module for High Current Applications

March 20, 2024
Renesas latest power module delivers the highest efficiency (up to 94% peak) and fast time-to-market solution in an extremely small footprint. The RRM12120 is ideal for space...

Empowering Innovation: Your Power Partner for Tomorrow's Challenges

March 20, 2024
Discover how innovation, quality, and reliability are embedded into every aspect of Renesas' power products.

Article: Meeting the challenges of power conversion in e-bikes

March 18, 2024
Managing electrical noise in a compact and lightweight vehicle is a perpetual obstacle

Power modules provide high-efficiency conversion between 400V and 800V systems for electric vehicles

March 18, 2024
Porsche, Hyundai and GMC all are converting 400 – 800V today in very different ways. Learn more about how power modules stack up to these discrete designs.

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!