What is haskell code introspection?

Yesod Book has a paragraph:

The Haskell pattern is essentially Haskell, which generates the Haskell Abstract Syntax Tree (AST).

Theres actually more power in TH than that, since he really can understand the code. However, we do not use these objects in Yesod.

What does it mean to view the code and what can you do with this function?

+5
source share
1 answer

Yesod's Haskell pattern code is used only to generate code. In this sense, this is a strict replacement for the template. Instead of using the Haskell template, we could manually write the conversion from the syntax of the route file to the code that you must write manually, and you could write the equivalent code yourself.

With introspection, you actually look at the existing information that the compiler has and makes decisions. For example, you can find all instances of the Show class and create a String with this list. This approach may be useful in some cases, for example, to automatically create a test suite. A commentary in the book states that Yesod never does this.

+8
source

Source: https://habr.com/ru/post/1274313/


All Articles