I've been leaning pretty heavily on the new C# 3.0 features while
simultaneously playing around with Haskell and other FP-oriented
languages. One problem that comes up often is the lack of a function
composition syntax.
For instance, there's this bit of code in one of my projects:
/* Convert all doc files in the directory
to plain text, strip out extraneous formatting,
and run them through the summary parser */
var results = filenames.ConvertAll
(file =parseSummary(cleanTxt(docToTxt(file))))
It's not awful. It's just not ideal. In haskell I would just use the
dot notation:
map (parseSummary . cleanTxt . docToTxt) filenames
It's more readable and there's less parenthesis overload.
An alternative is to have a larger list of ConvertAll statements.
Assuming there's no compiler magic happening, this seems like a much
slower approach, although it is more readable than my first example.
var results = filenames
.ConvertAll(docToTxt)
.ConvertAll(cleanTxt)
.ConvertAll(parseSummary)
I'm sure other people trying to adopt a more functional style in C#
3.0 have come up against this. Has a popular pattern emerged for
dealing with this?
Cheers,
kd