LtU Forum

High Performance and Generality - Functional Programming

Generative Code Specialisation for High-Performance Monte-Carlo Simulations

...we use functional programming to reconcile high performance and generality in simulators based on Monte-Carlo simulation. Moreover, we have successfully parallelised the kinetics simulation, which required a new technique as the simulation is based on a Markov-chain. This makes out approach future proof in the light of the current trend in hardware to add extra parallelism instead of increasing single-threaded performance.

Extensible Pattern Matching via a Lightweight Language

New draft of a paper by the F# team: Extensible Pattern Matching via a Lightweight Language Extension

By Don Syme, Gregory Neverov, James Margetson

Abstract
Pattern matching of algebraic data types (ADTs) is a standard feature in typed functional programming languages but it is well known that it interacts poorly with abstraction. While several partial solutions to this problem have been proposed, few have been implemented or used. This paper describes an extension to the .NET language F# called active patterns, which supports pattern matching over abstract representations of generic heterogeneous data such as XML and term structures, including where these are represented via object models in other .NET languages. Our design is the first to incorporate both ad hoc pattern matching functions for partial decompositions and “views” for total decompositions, and yet remains a simple and lightweight extension. We give a description of the language extension along with numerous motivating examples. Finally we describe how this feature would interact with other reasonable and related language extensions: existential types quantified at data discrimination tags, GADTs, and monadic generalizations of pattern matching.

Don Syme's blog introduces the paper:

  • How we combine total, partial and parameterized active patterns in one unified mechanism
  • Examples of using active patterns to match on LazyLists, Complex numbers, .NET Objects, strings using Regular Expressions, XML data, Data structures and F# Quotation values.

"Declarative" or "Functional"

I was playing around for some time with "functional" thing like Haskell and Erlang. Actually I think things like "Scala" (on JVM) and "F#" (on CLR) are very promising.
But I came across with a new view. I know features like "first class functions" and "concurrency"(in Erlang) are very useful.
Now my question is, in syntax level, is to be declarative as important as to be functional?
(Please include enhancements like multiple assignments and list comprehensions in to be declarative.)

F# 1.9.1 released

F# 1.9.1 has been released with a bunch of new features. LTU readers would probably be interested in the work on unifying object oriented and functional code:

# Active Patterns. Active patterns give a form of extensible pattern matching on abstract values. F# active patterns allow you to pattern match against .NET object values such as XML, System.Type values and LINQ Expression trees. In this redesigned version they become an official part of the language and some novel additions give a lightweight and non-intrusive mechanism to both partial patterns, parameterized patterns and "complete" decompositions (views) of types.

# Implicit Class Construction. This lovely feature makes writing classes considerably more succinct and helps to further bridge the gap between type-inferred functional programming and object-oriented programming.

More info is available at Don Syme's blog here.

Early Programming Languages (A Logic Puzzle)

Chris Okasaki (of Purely Functional Data Structures fame) gives us Early Programming Languages (A Logic Puzzle)

Try not to use your domain-specific knowledge.

Aldor going open source

According to the website, Aldor will be open source soon. See also: an old call to open the source, with a link to an online petition, and a recent and as-yet-unanswered query on the Aldor mailing list about the opening of the source.

In a related note, there was a patch to Aldor that I found a few years ago called "Aldor--", but search engines are useless in helping me find this. Does anyone remember this?

Deliverable code?

I wonder what Ltuer's think about deliverability? What is deliverable code? When I think about dynamic vs. static languages a big difference is the nature of the end product. A scripting language might conclude with a script deliverable, but does anyone want to deliver a script? Dynamic languages are "programmer friendly" but the final compiled deliverable is almost certainly "compromised" (ie slower or less safe). Languages like Java and C# require an intermediate virtual machine. This is only acceptable due the pervasiveness of the environments and probably compromises other languages using the VM. Can we have it both ways? Good deliverable code and a highly productive development environment? For example I have occasionally developed an application in Lisp and then converted it to C, (but not recently). Surely there is a better way?

Why can't you push instructions in MSIL/JVML

Doesn't it seem like a good idea to be able to push instructions onto the stack in the MSIL and JVML, and evaluate them later on?

Generators/Iterators and lazy evaluation

Hi all

I've been using OCaml for a year or so building an interpreter/compiler for the Python programming language as a research project.

It's worked pretty well for most part, but I'm trying to implement some of the features of Python involving 'lazy' features, such as generator functions and list comprehensions.

A generator in Python can be thought of as an arbitrarily generated 'lazy list'. As an example
the following is a generator capable of generating powers of 2 upto a max value.

def pow2(max):
  start = 0
  while (start .lt. max):
    yield 2^start
    start += 1

The 'yield' statement is the point where the function returns the next value and suspends itself until the next time it is 'forced'. At that time it resumes execution where it left off.

OCaml makes this particularly hard to implement this due to lack of 'control flow' features, including even a call/cc. The only way I can see right now is breaking this code down into little functions and keeping track of the right function to call the next time.

I've been thinking about whether I can express this in some elegant way in some lazy construct in OCaml, since this is basically a form of 'lazy' evaluation. However, I come from the C world and am not quite used to 'lazy' thinking :) Any ideas?

Live coding festival and conference

I hope this is relevant here, with the recent interest in the SuperGlue paper.

There will be a festival of live coding in Sheffield, UK from 20-22nd July 2007. There's a call for participation out right now:

http://livecode.access-space.org/

It is affiliated with TOPLAP, and supported by arts funding, so is particularly focused on live programming applications in music and video, with live performances being an important part of the programme. However, contributions on the computer science and philosophy side are very much welcome and indeed expected.

While I'm here, here's a paper I'm really enjoying, which I have not seen mentioned here yet:
http://akustik.hfbk.net/publications/AlgorithmsToday.pdf

XML feed