Is there any Template Haskell tutorial for someone

2020-05-22 08:19发布

I wanted to learn Template Haskell but all tutorials I find either assume that you learned lisp and know what lisp macros are, or that you know some cs theory jargon - things as splices, quasiquotations, etc... - or some theoretical results about macros.

I can't code a single line of lisp (and, though I intend to do this some day, I don't have the time to learn it right now). Haskell is my very first functional language and I learned it to the point that I can regularly code in it, use monads, applicative, understand the type system, etc... but I don't know much (also want to learn but I'm too stupid for it... :P) about the theoretical cs stuff behind it. So I'm oblivious to the jargon I typically find on TH tutorials.

So, the question is: is there a tutorial about TH for someone who code Haskell, not as a professional computer scientist, but just as a guy who uses programming for his daily chores, who learned Haskell as his first functional language? Maybe a introduction to macros and meta-programming that use TH as example?

Thanks all. :)

3条回答
干净又极端
2楼-- · 2020-05-22 08:20

The best introductory tutorials to Template Haskell I know of are two documents by Bulat Ziganshin. The links from the Haskell Wiki seem to be broken at the moment, however you can access them via archive.org:

查看更多
男人必须洒脱
3楼-- · 2020-05-22 08:24

Also the original paper Template metaprogramming for Haskell by Tim Sheard and Simon Peyton Jones might be helpful:

Abstract

We propose a new extension to the purely functional programming language Haskell that supports compile-time meta-programming. The purpose of the system is to support the algorithmic construction of programs at compile-time.

The ability to generate code at compile time allows the programmer to implement such features as polytypic programs, macro-like expansion, user directed optimization (such as inlining), and the generation of supporting data structures and functions from existing data structures and functions.

Our design is being implemented in the Glasgow Haskell Compiler, ghc.

查看更多
Explosion°爆炸
4楼-- · 2020-05-22 08:40

No, I don't think there are any great introductory tutorials to Template Haskell. The best way to learn is to look at examples, or:

I never found Lisp was a requirement, however there is terminology to learn, like for any domain-specific library.

查看更多
登录 后发表回答