4 ms·
Can you give an example of something you can implement with a Lisp macro, but you can't implement with Haskell?
by ntoshev 18y ago
Can 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.