Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Template Haskell allow arbitrary IO operations during compilation?

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.

like image 637
Petr Avatar asked Dec 09 '12 08:12

Petr


1 Answers

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.

like image 62
Carl Avatar answered Oct 19 '22 22:10

Carl