Monday, November 30, 2009

Functional C

I've been toying around with the idea of a new language and the functional paradigm is definitely where I want to focus my efforts, but the question is, what would make it stand out from the rest of the field? I haven't looked at all of them, but my impression is they typically are oriented to more application-style programming. In other words, they focus on writing applications vs. something more low-level, like operating systems and embedded systems.

So, what I'm thinking is that we need a good functional programming language that can be used for systems development. This is a bit iffy as one of the key features of C, for example, is that it has very predictable behavior. Functional languages, however, don't have this as they typically have garbage collection. Also, Haskell has laziness, which isn't very predictable as well.

Can this be done? I think so, but it has to be done carefully. Without garbage collection, I'm not really sure how to best do this. Granted, a very smart compiler could translate any recursive functions into loops, but I'm not sure if that's enough. It may be as there's nothing that says you couldn't have loops in functions where mutable variables are localized and can only be used within the loop.

Now, what would the benefits of this be? Well, the fact that functions will, by default, be pure allows programs written in this hypothetical language to be run concurrently without worrying about concurrency issues as much as with C. This will be nice in applications which inspired me to think about this language: high performance computing. A recent article stated that using Haskell instead of C for one system resulted in a significant performance increase. My guess is that this is due to better concurrency.

One may think that this means that Haskell is good enough, but what about embedded systems that require more predictability? I'm guessing that robotics falls into this category. Random garbage collection could prove interesting. In fact, I recall someone stating that they built a robot or something similar that had software written in Java. If true, it garbage collected itself into a wall.

Now, some other things that I think should be in the language before I sign off:
  • Support for all of the different data types as C so that we can perform the same kind of bit manipulation as we can easily do in C.
  • Arbitrary precision arithmetic. Large number crunching and ensuring that the results are accurate, especially for financial systems, are common enough that I don't see why these shouldn't be part of any new language.
  • Good string processing. Processing data is a very important reason to use computers, so let's make it easy.
  • Fail-fast capabilities. This is one of the great features of Erlang and it should be incorporated if possible. How this will work will be an issue because I don't want this to run on a VM, which is how Erlang works.
  • Good threading with message passing/STM/something. Perhaps a combination of one or more as they both have their benefits.
That's all for now. I'm sure I've forgotten something I thought of, but I wanted to get this out. I think it's an important idea because if this can be done, I think it'll be a great boon for proponents of functional programming as it now can be used where C has been the best if not the only choice for developing systems. As for the name of the post, well, that's my unofficial code-name for this particular language as it encompasses what I believe it needs to be. Of course, this also led me to think of something else: can we program in C in a functional manner? Perhaps all this language has to be is a high-level language that gets translated into C written in a functional manner? Time will tell.

Labels: , , ,

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home