3 ms·
Haskell's "Template Haskell" system is pretty sophisticated... And challenging enough to be some deep black magic. You end up being able to reify the entire Ha
by tel 12y ago
Haskell's "Template Haskell" system is pretty sophisticated... And challenging enough to be some deep black magic.
You end up being able to reify the entire Haskell syntax tree from "quoted" fragments, manipulate and generate a modified tree, and then "print" it back into program flow.
Totally capable, but not terrifically fun. It also has some compilation restrictions which are annoying if necessary.
- dllthomas 12y agoI just (last night) dug into some TH hackery. I put together a quasiquoter for testing/debugging that would walk a do block and decorate every statement with (`onException` ...) set up to print the source location when an exception is thrown. I actually had to first parse with haskell-src-exts to get the location info, and currently I'm turning it into an ExpQ by pretty-printing and reparsing - which I don't love, but gets the job done. https://github.com/dlthomas/snowdrift/compare/5094b1ca0e5002c0d12a7f714b083d88d450ddb3...e7bf8ac8b6320fcc46233248170920fc97d805c9 https://github.com/dlthomas/snowdrift/compare/5094b1ca0e5002...
- judk 12y agoTH also ruins Haskell by inserting inivisble code with spooky action at a distance, where you have to pre-import symbols that TH will insert later, and compiler errors refer to code defined somewhere else but print line numbers of where the generated code is inserted. TH needs a compiler!