Speaking of points, back to the subject in hand.
My DSL is, in large part, based around a type Expr<T>
There are two flies in the ointment.
Ointment fly number 1: you can't freely overload the indexing operator.
I would like to be able to write xs[i] to denote the JavaScript expression for the ith element of the array xs. Tragically, I can't do this. Here's what the implementation might look like if you could:
public static Expr<T>
But, noooo, I can't do this because this has to be defined in the Expr<T> class and that means this has type Expr<T> rather than Expr<T[]>, which is what is required. Instead I have to provide some awkward named function, Ith(xs, i) to do the job. Ugh.
Damn you, C# !
Ointment fly number 2: you can't freely overload the << operator.
I would like to express assignments in my DSL as x := y or x <- y, but I can't do that because C# won't let you create new infix operators. Hmm, well, I reckon << is hardly ever used, so maybe I could hijack x << y instead for assignment. It has as slightly tainted C++ flavour, but it's the best thing on offer.
But, noooo, I can't do this because if I write
public static Act operator <<(Var<T>
I get a complaint from the C# compiler that not only is the first argument not of type Expr<T> (the hosting class), but the second argument is not a plain old int! Great googly moogly, what were they thinking? Even if I wanted to implement << as bitwise left shift in my little DSL, I couldn't because of the idiotic second constraint. Instead I have to provide some awkward named function, Set(x, e) to do the job. Ugh.
Damn you, C# !
Why would you expect any of this to work?
I just so happens I spent most of my life doing functional programming (I taught Haskell, I worked on the Mercury language team for a very long time). In sane, modern languages (i.e., ones invented since ~1970 by people who actually passed a few hard exams -- OO, I am not talking about you) this sort of thing is done as a matter of course.
Arghghghghghgh.
2 comments:
Not because I don't believe you, but because I'm very interested in what this DSL looks like, can you publish just a snippet of what a basic example looks like in it? I'm curious to see what the syntax looks like...
Hi Ilya! Great to hear from you. I've put up a new post in response to your question. I'd love to hear your feedback.
Post a Comment