Hacker News new | past | comments | ask | show | jobs | submit login

How often are you doing something that needs to be turned into a DSL, or is this something that you do all the time once you grok it?



More often than I'd like to. In an ideal world, language designs would be perfect out of the box, and the right abstraction for expressing what I want to express would always be available without me having to do anything. Alas, in the real world, languages have limitations, and you can either metaprogram them away or put up with them.

For example, a while back I was investigating a general framework for expressing various types of self-balancing search trees without tediously reimplementing the same ideas over and over:

(0) A search tree is either a leaf or node. A node is a alternating sequence of subtrees and individual elements, beginning and ending with a subtree.

(1) Rebalancing a tree preserves the sequence obtained from traversing it in-order.

(2) In the specific case of binary search trees, there exist two kinds of rotations: 3-rotations (rebalancing the sequence “a,x,b,y,c”, where “a,b,c” range over subtrees and “x,y” range over individual elements) and 4-rotations (rebalancing the sequence “a,x,b,y,c,z,d”, where “a,b,c,d” range over subtrees and “x,y,z” range over individual elements).

(3) It is very convenient to manipulate purely functional search trees using zippers, for more or less the same reasons it is very convenient to manipulate imperative search trees using iterators. Zipper types can be obtained from tree types using a generic procedure (given the recursive type “T = μR.F(R)”, find the derivative of “F(R)” with respect to “R”, then instantiate it at “T = R”)... if only you could express this procedure in the first place.


Thanks for the reply!




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: