What is the 'expression problem'?

我对这是什么有一个粗略的想法,但如果有人解释他们认为简洁直观的“表达问题”,我很乐意听到它。


Watch this lecture.

The idea is that your program is a combination of a datatype and operations over it. The problem asks for an implementation that allows to add new cases of the type and new operations without the need for recompilation of the old modules and keeping static type safety(no casts or runtime type checks).

It's interesting to notice that in functional programming languages it's easy to add new operations, but hard to add cases to the datatype. While in an OO language it's the other way round. This is one of the big conceptual differences between the two programming paradigms.


The idea behind the problem is that text is 1 dimensional. Even if you have lines and columns, you generally read it, word by word, line by line. So does the compiler.

And you try to represent some kind of 2 or more dimensional data in it. For example a table in row-mayor order looks like this:

((A, B, C), (D, E, F), (G, H, I))

In this representation, it's quite easy to add a new row at the end, without touching the rest:

((A, B, C), (D, E, F), (G, H, I), (J, K, L))

But adding columns is problematic a bit, you need to touch it 4 different places:

((A, B, C, M), (D, E, F, N), (G, H, I, O), (J, K, L, P))

You generally run into this problem in practice, when dealing with abstract classes: it's quite easy to add a new subtype as a new module, but when you add a new abstract method, you'll need to touch all the modules and add it; you need to do the same thing in many places. Normally you make abstractions to protect against these repetitive things.

There is no solution to this problem as long as you use 1D representation.

The solution to this problem would be an editor that can let you edit these table like things like a real table and not like text (in an Excel like view, where you can conveniently add new columns and rows).


这篇文章也有关于解决Clojure问题的文章,但是这个问题是用Java表达的,所以即使你不了解Clojure,尤其是在小图表的帮助下,它也应该是有意义的。

链接地址: http://www.djcxy.com/p/22900.html

上一篇: 什么是图灵完成?

下一篇: 什么是“表达问题”?