Monadic parser combinators, a noteworthy aside
Posted by Brian on December 7, 2007
So I’ve been blissfully coding and blogging about monadic parser combinators for the past few days, enjoying using the new C# features to tackle one of my old-favorite tasks. And then today I was browsing around and discovered that I’ve been beaten to the punch. :) LukeH has already blogged about monadic parser combinators in C#, and furthermore, he’s doing a better job than I am, in that he actually knows the new LINQ syntax sugars. From scanning his post, I can see that the new LINQ sugars that allow you to write
from x in p1 from y in p2 from z in p3 select f(x,y,z)
can (given a suitable parser representation type) be used in place of the heavier-syntax lambdas I’ve been using like so
p1.Then(x => p2.Then(y => p3.Then(z => Return(f(x,y,z))
And where clauses can automagically do stuff like Sat… Wow, that is so much more syntactically elegant than what I have been doing. I feel foolish now for going as far as I have without leveraging this syntax. Well, now I have a good excuse to go learn the new LINQ syntax sugars!
I don’t think this will invalidate any of the structure of what I’ve done so far in my previous blog entries on parser combinators, but I have a lot of code to go reformat and lightly rework now. :)
Anyway, this short post is just to inform everyone of my previous ignorance. :) I’m going to go learn the rest of the LINQ stuff now, map it into my general understanding of functional programming and monads, and then return to blogging again about parsers, only this time with more readable code, I expect. Wish me luck!