Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

Look at the uses for Template Haskell, for example.

That's basically Haskell's macro system. And it's used quite a lot, though it's kind of arcane.

If you want to create an abstraction that defines one or several data types, you'll think hard about whether you can use some kind of type-level programming instead—but if that's not possible, or not convenient, you can use TH macros.

For example, the `lens` package defines TH macros for creating special kinds of accessors that are tedious to write by hand.



using macros to deal with boilerplate, although useful, though is of a different order than things that simply cannot be expressed without macros


Which things cannot be expressed without macros? Macros run at compile time, and just output normal code in the language.

I think being able to generate types is a very useful and important use of macros. In fact, (depending on whether or not your macros can have side effects) you could use macros to implement something like F#'s type providers.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: