Would it be possible to do the same thing in Haskell using partial function application, where the first argument is the name of the tag and the second argument makes the "<" ">" tags and applies string concatenation?
def tag(tag):
def render(*body):
return '<{tag}>{body}</{tag}>'.format(
tag=tag, body=''.join(body))
return render
html = tag('html')
body = tag('body')
h1 = tag('h1')
p = tag('p')
I also should note that, while the macros in this case could be obviated by approaching the problem slightly differently, I don't think that's true of Lisp macros in general. I don't want to be be too harsh to this particular blog post—coming up with a two-or-three line motivating example that's accessible to a general audience without being contrived is very hard! But one consequence of the slightly-contrived nature of the example in this post is that it's very easy to come up with non-macro ways of solving the same problem, as demonstrated above. deftag "html"
but instead would have to write something like html = tag "html"
I'm not sure whether you could get around that limitation using Template Haskell (never tried it).So its again Lisp all over again.
My bad. It's called Lisp with types. From: https://en.wikipedia.org/wiki/ML_(programming_language)
Now. Haskell does look like a impractical scheme. Beyond that, today if you want it, you have typed racket.
For a lot of people you could just go ahead use Racket/Lisp instead of Haskell instead.