by zenhack · 6y ago · 0 comments
Haskell has TemplateHaskell, which can be used for macro-like things, but it's substantially less ergonomic, not because Haskell isn't "homoiconic", but because the grammer is actually really complex and non-obvious. There's tons of little things that you don't think about when writing Haskell code, but you have to deal with when manipulating it. For example:
https://hackage.haskell.org/package/template-haskell-2.15.0....
That's a node in the AST that stands for something that is at most one character in the source text, and usually zero. So code manipulating this stuff gets really verbose and clunky. It's still powerful, but it's not the same.
As a side project, I'm actually working on an ML-family language with a macro system. It still has a more traditional ML-style syntax, but it is simple so working with it should be comparatively ergonomic. In an ML you wouldn't frequently want to be working with loosely defined data structures anyway; the first thing you'll do is convert it to a more strongly typed form that captures what you really want to be manipulating.
When I'm digging through a large body of code looking for subtle bugs, I want the code to be boring but not bland. By that I mean, yes, all of the bits should be obvious, because I'm having to contend with the cartesian product of all of the bits. But if everything is self-similar top to bottom, there are no landmarks. It becomes very easy to get 'lost' in the code and have trouble telling if the next candidate for debugging is 'up', 'down' or sideways in the call stack.
Fractals are really cool to look at, but they're murder for navigation purposes.
Are they? They imply that the structure is self-similar, which is a good trait for a structure, and makes it easy to read it at any level and get what's going on.
That's what trees are, lists of lists are, strings of characters are, etc.
>But if everything is self-similar top to bottom, there are no landmarks.
The specific functions called at each level are the landmarks.
The problem is that a custom language so built is harder for newcomers to the project to get to grips with. If it's a super common problem, and the solution gets popular, it might work out - see e.g. Rails with its DSLs for migrations, routes, etc. But that's a small fraction of problems. Hired developers don't really want to learn you custom thing, too, as it reduces their market value.
Lisp/Smalltalk DSLs only expand your capabilities here to syntactic abstraction / code generation. But the overall principle is the same.
The PLT literature is full of programming languages with simple and easily-serialized syntax. It's not all about LISP or Church's lambda calculus or whatever, there's plenty more out there.
As one example, the bit of Haskell syntax you mention is only "complex and non-obvious" because the Haskell community has yet to internalize the ideas that PLT research has come up with, as to how laziness and strictness should be specified, interact etc. in a programming language (i.e. polarity, focusing, call-by-push-value).
Could you how those ideas should be used in practice? I'm a Haskell programmer and vaguely familiar with the ideas you mention but it's not clear to me exactly how they fit into a practical language.