LtU Forum

Ivory Towers and Gelfand's Principle

I read today a rant on pedadogical philosophy by Doron Zeilberger via Philip Wadler's web log.
The first one, due to my colleague and hero Israel Gelfand, I will call the Gelfand Principle, which asserts that whenever you state a new concept, definition, or theorem, (and better still, right before you do) give the SIMPLEST possible non-trivial example. For example, suppose you want to teach the commutative rule for addition, then 0+4=4+0 is a bad example, since it also illustrates another rule (that 0 is neutral). Also 1+1=1+1 is a bad example, since it illustrates the rule a=a. But 2+1=1+2 is an excellent example, since you can actually prove it: 2+1=(1+1)+1=1+1+1=1+(1+1)=1+2. It is a much better example than 987+1989=1989+987.

While writing a reply on LTU, I thought about modifying this principle to programming language design: If an example has a solution that is nearly as good without a given language feature, then that example is not a good motivation for that feature. Perhaps not following this principle is partly what earned FP it's ivory tower reputation.

Researchers love to generalize the heck out of any given feature, to add linguistic support for minor issues, etc. etc. It seems that as a result, PL researchers, particularly FP researchers, have a (deserved and undeserved) reputation for solving problems that aren't really there.

I'm not suggesting that every exploration must be practically motivated. Indeed, it's fun and educational to explore what can be done for its own sake. Was laziness ever practically motivated? I'm not aware that it was, but it certainly lead to some very important breakthroughs, most significantly how to satisfactorily deal with impure effects in a pure language.

However, when it comes to promoting a given language for wider use, features should be chosen to solve practical programming problem, preferably the problems that a niche finds unsatisfactory. (Or should find unsatisfactory... customers usually don't know what they need.)

What practical problems in what niches are LTU readers aware of?

Functional anti-memoization

In Haskell, data structure elements are memoized. That is, the function that creates say, an element of a list is called at most once. After the first evaluation, the resulting value is saved away in case it is ever needed again. This is great for things like the infinite list of Fibonacci numbers...

fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
...but it can lead to excessive memory in situations like...
main = print (length list, sum list)
list = [1..10000000]
...where at some point the entire list will need to be in memory. You could have avoided the large memory usage by traversing the list in a linear way, building up the length and sum at the same time, rather than in sequence.

Now imagine an evaluation régime, where instead of memoizing each data element (for later use), we call all of the functions which have a pointer to this element. Afterwards, no more pointers to this element will exist, so we can reclaim its memory. It changes the rule "evlaute a data item at most once" into "evaluate a data item as most once, and be sure to call anything that depends on it immediately, because it is short lived". Is there a name for this evaluation strategy, and any programming languages which implement it?

MetaPlatform 0.0.1

I just released my new metaprogramming-oriented system (JVM version):

MetaPlatform

Formal semantics for working programmers

Since DSL (Domain Specific Language) is almost an everyday topic for many programmers, I wonder how should a working programmer proceed to define and acturally use a formal semantics for her DSL? I do not mean a group of equations in LaTeX, but an effective method to help to reason about the programs within reasonable constraints for common projects. (Or, is there even bigger advantage to be taken?) To be specific, I was wondering if coq and isabelle and nusmv alike are usable for common projects? Is the cost (exclude the cost of learning) too high? And why? Thank you!

Amber: Eiffel/Ruby inspired language for the Parrot VM

Came across this on Freshmeat:

Amber: "Amber for Parrot is a scripting language for the » Parrot virtual machine. It combines the traditional advantages of scripting languages with support for software correctness and large-scale software engineering."

It's described in self-deprecating terms, but it's interesting in several ways:

  • Built in Eiffel and inspired by Eiffel
  • Targeting the Parrot VM instead of Java's
  • Implements "contract hardening" which sounds intriguing
  • Not just another functional programming language, of which there are so many...
  • I heard about it before LtU did

Ken Meltsner

Sawzall - a popular language at Google

Interpreting the Data: Parallel Analysis with Sawzall

"The query language, Sawzall, operates at about the level of a type-safe scripting language. For
problems that can be solved in Sawzall, the resulting code is much simpler and shorter – by a
factor of ten or more – than the corresponding C++ code in MapReduce."

ObjectiveCLIPS Released

ObjectiveCLIPS is a new programming environment designed for Cocoa, the native Mac OS X object system. ObjectiveCLIPS's originality come from the fact that it integrates the CLIPS expert system shell with Apple's Core Data technology and F-Script, allowing the creation of intelligent Cocoa applications with persistent object models and complex business rules. Developers can easily embed ObjectiveCLIPS in their application and take advantage of its inference engine and associated tools to implement their application logic. ObjectiveCLIPS unifies CLIPS facts with Objective-C Core Data objects, and allows for the manipulation of these objects in rules with the Cocoa-based F-Script language.

ObjectiveCLIPS is an open source software.

Neko 1.0

Hi,

I have just released Neko 1.0, which is an intermediate programming language with its embedable virtual machine. It might be very interesting for language designers since Neko have been designed so you can generate from your language to Neko and then reuse the virtual machine and libraries provided. You can then concentrate on the design and let Neko take care of the runtime.

More informations at http://nekovm.org.

If you have questions or comments, please feel free to ask.

large imperative code --> functional

(note the complementary thread)

Given an imperatively styled program in C, with complex shared state, how would people suggest converting it to functional style?


The program I'm working with is Chromium, which implements a stream-processing model over the OpenGL API, so that the calls from a graphics program (e.g. Quake) get turned into a stream of function calls that can be filtered/modified.

To do this, Chromium contains a "state machine" which tracks all state contained in OpenGL: lighting, raster-position, textures, matrix-stacks, etc. etc.


Via google I found HOGL, a functionalish Haskell binding for OpenGL that lets you do things like:

demo0 = runGraphics ( do
    w <- openWindow "Demo 0" (400, 400)
    print "Demo0 a very simple Hogl program"
    print "press any key to quit"
    draw w (WithColor blue
            (Translate (0,0,-50)
             (Scale (80,80,80)
              (Rotate 36 (1,1,0)
               (cube 1)))))
    getKey w
    closeWindow w
    )

- that is, you can do some state-changes (here setting the current color and changing the modelview matrix) in a functional style.


..anyway, how would people suggest to deal with a large state-machine like that in OpenGL? Are there tools out there for semi-automation of the process?

Invariants/Contracts vs. types

I noticed the new (to me) language "Qu" chooses to implement type-checking via invariants (see http://centrin.net.id/~marc/example.html).

(invariants, contracts, validators - all refer to the same thing here. any further names?)

Since this is more expressive and potentially "safer" than any typing systems I'm aware of, I'm wondering

  • how much prior work has been done on such systems?
  • why isn't this more common as a safety mechanism in dynamic languages?

  • and perhaps more difficult:
  • what is the "most complex" STATIC type system currently around, in terms of doing compile-time analysis for such value-constraints?

This appears to have been discussed very briefly here, but maybe I missed something.

XML feed