Content deleted Content added
small clarification |
|||
(34 intermediate revisions by 14 users not shown) | |||
Line 1:
The '''expression problem''' is a challenging problem in [[programming language]]s that concerns the extensibility and modularity of statically typed data abstractions. The goal is to define a data abstraction that is extensible both in its representations and its behaviors, where one can add new representations and new behaviors to the data abstraction, without recompiling existing code, and while retaining static type safety (e.g., no casts). The statement of the problem exposes deficiencies in [[programming paradigm]]s and [[programming language]]s. Philip Wadler, one of the co-authors of Haskell, has originated the term.
== History ==
Line 18 ⟶ 17:
| first1= John C.
| publisher= IFIP Working Group 2.1 on Algol
| pages=
| url= https://www.cs.tufts.edu/~nr/cs257/archive/john-reynolds/procedural-data-structures.pdf
}}
</ref> Reynolds discussed two forms of Data Abstraction: User-defined Types, which are now known as [[
Fifteen years later in 1990, [[William Cook (computer scientist)|William Cook]]<ref name="CookOOPvsADT">
{{cite book
Line 37 ⟶ 31:
| title= Foundations of Object-Oriented Languages (FOOL), REX School/Workshop
| ___location= Noordwijkerhout, The Netherlands
| publisher= Springer Berlin Heidelberg |pages=
| chapter= Object-Oriented Programming versus Abstract Data Types
|series= Lecture Notes in Computer Science
|volume= 489
|doi= 10.1007/BFb0019443
| chapter-url= https://link.springer.com/chapter/10.1007/BFb0019443
| isbn= 978-3-540-46450-1}}
</ref>
applied Reynold's
Most importantly, he discussed situations in which there was more flexibility than
Reynolds considered, including internalization and optimization of methods.
At ECOOP '98, [[Shriram Krishnamurthi]] et al.<ref name="Synth">
Line 50 ⟶ 47:
| title=Synthesizing Object-Oriented and Functional Design to Promote Re-Use
| url=https://cs.brown.edu/~sk/Publications/Papers/Published/kff-synth-fp-oo/
}}</ref> presented a design pattern solution to the problem of simultaneously extending an expression-oriented programming language and its tool-set. They dubbed it the "expressivity problem" because they thought programming language designers could use the problem to demonstrate the expressive power of their creations. For PLT, the problem had shown up in the construction of DrScheme, now [[
{{cite
| title= Modular object-oriented programming with units and mixins
| date=1999 | doi=10.1145/291251.289432 | last1=Findler | first1=Robert Bruce | last2=Flatt | first2=Matthew | journal=ACM SIGPLAN Notices | volume=34 | pages=94–104 | doi-access=free }}</ref> via a rediscovery of [[mixin]]s.<ref name="Mixins">{{cite thesis |type= PhD
| last= Cook | first= William | date= 1989
| title= A Denotational Semantics of Inheritance | publisher= Brown University
Line 71 ⟶ 67:
| first3= Matthias
| isbn= 978-0897919791
| s2cid= 5815257
}}</ref> To avoid using a programming language problem in a paper about programming languages, Krishnamurthi et al. used an old geometry programming problem to explain their pattern-oriented solution. In conversations with Felleisen and Krishnamurthi after the ECOOP presentation, Wadler understood the PL-centric nature of the problem and he pointed out that Krishnamurthi's solution used a cast to circumvent Java's type system. The discussion continued on the types mailing list, where Corky Cartwright (Rice) and [[Kim Bruce]] (Williams) showed how type systems for OO languages might eliminate this cast. In response Wadler formulated his essay and stated the challenge, "whether a language can solve the expression problem is a salient indicator of its capacity for expression." The label "expression problem" puns on expression = "how much can your language express" and expression = "the terms you are trying to represent are language expressions".
Others co-discovered variants of the expression problem around the same time as Rice University's PLT, in particular Thomas Kühne<ref name="K">
{{cite book|last=Kühne|first=Thomas|title=A Functional Pattern System for Object-Oriented Design|year=1999|publisher=Verlag Dr. Kovac|___location=Darmstadt|isbn=978-3-86064-770-7}}</ref> in his dissertation, and Smaragdakis and Batory<ref name=SB>
{{cite
Some follow-up work used the expression problem to showcase the power of programming language designs.<ref name="Scala0">
{{cite
|
| first1=Matthias | last1=Zenger
| first2=Martin | last2=Odersky
| title=Proceedings of the sixth ACM SIGPLAN international conference on Functional programming | pages=241–252
| citeseerx=10.1.1.28.6778
| year=2001
| doi=10.1145/507635.507665
| isbn=1-58113-415-0 }}</ref><ref name="Scala">
{{cite
|
| chapter-url=https://homepages.inf.ed.ac.uk/wadler/fool/program/final/10/10_Paper.pdf
| first1=Matthias | last1=Zenger
| first2=Martin | last2=Odersky
| title=FOOL 2005
| publisher=ACM
| citeseerx=10.1.1.107.4449
| year=2005
}}</ref>
The expression problem is also a fundamental problem in multi-dimensional Software Product Line design and in particular as an application or special case of [[FOSD
== Solutions ==
There are various solutions to the expression problem. Each solution varies in the amount of code a user must write to implement them, and the language features they require.
* [[Multiple dispatch]]<ref name="Chambers & Leavens, Multi-Methods">{{cite journal|last1=Chambers|first1=Craig|last2=Leavens|first2=Gary T.|title=Type Checking and Modules for Multi-Methods|journal= ACM
*
* [[Coproduct]]s of [[functor]]s<ref>{{cite
|author = Wouter Swierstra
|title = Data Types à La Carte
Line 115 ⟶ 113:
|publisher = Cambridge University Press
|doi = 10.1017/S0956796808006758
|s2cid = 21038598
|doi-access = free
}}</ref>
* [[Type class]]es<ref name="Wehr & Thiemann, JavaGI Type Classes">{{cite journal|last1=Wehr|first1=Stefan|last2=Thiemann|first2=Peter|title= JavaGI: The Interaction of Type Classes with Interfaces and Inheritance|journal= ACM
* Tagless-final<ref name="Carette et al.,
Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages">{{cite journal|last1=Carette|first1=Jacques|last2=Kiselyov|first2=Oleg|last3=Chung-chieh|first3=Shan|title=Finally Tagless, Partially Evaluated: Tagless Staged Interpreters for Simpler Typed Languages|journal=J. Funct. Program.|date=2009|volume=19 |issue=5 |pages=509–543 |doi=10.1017/S0956796809007205 |s2cid=6054319 |url=http://okmij.org/ftp/tagless-final/JFP.pdf}}</ref> / Object algebras<ref name="Oliveira & Cook, Object Algebras">{{cite journal|last1=Oliveira|first1=Bruno C. d. S.|last2=Cook|first2=William R.|title=Extensibility for the Masses: Practical Extensibility with Object Algebras|journal=Ecoop '12|date=2012|url=http://www.cs.utexas.edu/~wcook/Drafts/2012/ecoop2012.pdf}}</ref>
* Polymorphic Variants<ref name="Code Reuse Through Polymorphic Variants">{{cite
== Example ==
Line 127:
<syntaxhighlight lang="c#" line="1">
{
int Eval();
}
{
{
N = n;
}
public int Eval()
Line 147:
}
{
{
Left = left;
Line 155:
}
public int Eval()
Line 165:
}
{
}
</syntaxhighlight>
Using this library we can express the arithmetic expression
<syntaxhighlight lang="c#" line="1">
{
{
Left = left;
Line 183:
}
public int Eval()
Line 194:
</syntaxhighlight>
However, if we wish to add a new function over the type (a new method in C# terminology), for example to pretty print an expression, we have to change the
=== Problem
Let us redesign the original library with extensibility in mind using the ideas from the paper ''Extensibility for the Masses.''<ref name="Oliveira & Cook, Object Algebras" />
<syntaxhighlight lang="c#" line="1">
{
T Lit(int n);
Line 206:
}
{
public IEvalExp Lit(int n)
Line 219:
}
{
public static T AddOneToTwo(ExpAlgebra<T> ae) => ae.Add(ae.Lit(1), ae.Lit(2));
Line 225:
</syntaxhighlight>
We use the same implementation as in the first code example but now add a new interface containing the functions over the type as well as a factory for the algebra. Notice that we now generate the expression in
<syntaxhighlight lang="c#" line="1">
{
string Print();
}
{
{
N = n;
}
public string Print()
Line 248:
}
{
{
Left = left;
Line 256:
}
public string Print()
Line 266:
}
{
public IPrintExp Add(IPrintExp left, IPrintExp right)
Line 279:
}
{
}
</syntaxhighlight>
Notice that in
== See also ==
* [[FOSD
* [[Generic programming]]
* [[POPLmark challenge]]
== References ==
{{Reflist|2}}
== External links ==
*[http://homepages.inf.ed.ac.uk/wadler/papers/expression/expression.txt The Expression Problem] by [[Philip Wadler]].
*[http://www.uni-koblenz.de/~laemmel/paradigms1011/resources/xproblem.html Lecture: The Expression Problem] by [[Ralf Lämmell]].
*[http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Dr-Ralf-Laemmel-Advanced-Functional-Programming-The-Expression-Problem C9 Lectures: Dr. Ralf Lämmel - Advanced Functional Programming - The Expression Problem] at [[Channel 9 (discussion forum)|Channel 9]]
*[http://lampwww.epfl.ch/~odersky/papers/ExpressionProblem.html Independently Extensible Solutions to the Expression Problem, Matthias Zenger and Martin Odersky, EPFL Lausanne].
[[Category:Programming language design]]
|