As I'm trying to learn about TH I found out that it allows arbitrary IO
actions during compilation (see What's so bad about Template Haskell?). This seems quite dangerous to me. Why is that? Is it really necessary for some tasks? Or is it just a simplification of its design, to "toss everything impure into the IO
sin-bin"?
Update: I'd be also interested if there are any efforts at making a safe subset of TH that disallows arbitrary IO
operations.
One of the major intended uses for Template Haskell is building in constants from external resources, like large text values from files or build information (version, time, environment). Obviously, doing that requires system access.
Then it comes down to try to build a safe API for this, or just allow arbitrary IO. The latter was chosen out of how simple it is, and how easy it is to get a safe API wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With