5 ms·
An interesting question[0] was asked by ntoshev[1] in the discussion that ensued when this was submitted a little over five years ago[2]: > Can you give an
by ColinWright 13y ago
An interesting question[0] was asked by ntoshev[1] in the discussion that ensued when this was submitted a little over five years ago[2]:
> Can you give an example of something you can
> implement with a Lisp macro, but you can't
> implement with Haskell?
Much of that discussion is worth reading. The other submissions don't have much discussion.
[0] https://news.ycombinator.com/item?id=516208 https://news.ycombinator.com/item?id=516208
[1] https://news.ycombinator.com/user?id=ntoshev https://news.ycombinator.com/user?id=ntoshev
[2] https://news.ycombinator.com/item?id=516038 https://news.ycombinator.com/item?id=516038
- cynicalkane 13y agoMy somewhat neglected library Clearley (https://github.com/mthvedt/clearley https://github.com/mthvedt/clearley) uses a macro system, that lets you write parsers that look a little like pattern-matching functions. To do this, you need to be able to introspect, bind and lookup symbols, and data structures containing symbols, at compile time. You can't do this in Haskell. Template Haskell doesn't help, since IIRC it doesn't support looking up symbols in the same file. With Clojure, If you understand the JVM type system and performance, you can also write high performance DSLs using Clojure macros. https://github.com/clojure/core.logic https://github.com/clojure/core.logic allegedly is a project along these lines, but I haven't looked too much into it. It heavily uses Clojure protocols (which map to Java interfaces) for performance. I had been working on a code generator for Clearley, which sits neglected on my hard drive, but is able to perform just a little slower than unoptimized hand-written parsers. Since in Clojure compile/runtime separation is optional and off by default, you can use Clojure to generate Clojure code, making life a lot easier.
- Peaker 13y agoTemplate Haskell does support looking up the namespace in the same file.
- logicchains 13y agoAs Lisp macros are compile time metaprogramming, wouldn't the answer to this depend on whether Template Haskell is considered part of Haskell or just a compiler extension?
- ohyes 13y agoActually they're macro expansion time meta programming. Common Lisp also has compiler macros, which are slightly different (in addition to regular macros). Lisps generally run in an image, meaning you have full access to he full state of the program including the compiler/macro expander/etc, which you can run at runtime. So what about a program that reads a protocol off the wire, expands/compiles it to x86_64 assembly, and communicates over the wire with it (all in the same process and without calling any external compiler). Or maybe a program that collects runtime performance statistics and uses some stochastic method to improve the 'hot' pieces of code.
- chrisdone 13y agoIt's so completely trivial to generate examples of things that Lisp macros can do that Haskell's laziness cannot achieve, it muddies the subject. Try implementing lambda-case or anything written in template-haskell in laziness: you cannot. That's where Lisp macros shine. :-)
- TheCoelacanth 13y agoIt's also where Template Haskell shines.
- TheCoelacanth 13y agoThat's a good question, but the only answer in the thread is something that can easily be implemented in Template Haskell. genFoo :: String -> DecsQ genFoo name = [d| instance Foo $(return t) where quux = $(return f) |] where f = VarE . mkName ("quuxify" ++ name) t = ConT (mkName name) genFoos :: [String] -> DecsQ genFoos = foldl' (liftM2 (++)) (return []) . map genFoo