4 ms·
A lot of (but not all of) what you end up getting from Lisp macros ends up being not needed to be implemented with macros in Haskell anyway.
by shrughes 18y ago
A lot of (but not all of) what you end up getting from Lisp macros ends up being not needed to be implemented with macros in Haskell anyway.
- mattrepl 18y agoI've noticed the same thing with Clojure. I only dig into macros to remove boilerplate, like when using APIs provided in other JVM languages.
- swannodette 18y agoI've been using macros in Clojure to write my own object system. It seems to me that for serious meta-programming in Haskell, you have to use Template Haskell, and from what I've heard, it's not nearly as flexible.
- jrockway 18y agoIt seems to me that for serious meta-programming in Haskell, you have to use Template Haskell, and from what I've heard, it's not nearly as flexible. "seems" and "heard" is the best you can do? Try it, and you'll find that it's very easy to meta-program in Haskell, even without macros.
- ntoshev 18y agoCan you give an example of something you can implement with a Lisp macro, but you can't implement with Haskell?
- jrockway 18y agoSure. Consider the case of defining an instance of a type class: instance Foo Bar where quux = quuxifyBar -- terrible example Now, you want to follow the same pattern to declare "Foo Baz", "Foo Quux" and "Foo CannedAir". I hope you like copying and pasting, because that's how you do it without Template Haksell. In Lisp, it would be a simple matter of writing a macro, like this: (defmacro make-my-type-thing (type) `(instance Foo ,type ((quux (x) (,(intern (format nil "quuxify-~A" type)) x))))) Then you can: (eval-when (:compile-toplevel) (loop for i in '(Bar Baz Quux CannedAir) do (make-my-type-thing i))) Yes, the example is very contrived, and yes, Haskell ships with a lot of abstractions to make this case very uncommon. But in Haskell, you just can't treat your code as data -- it's code.