문제

I want to generate code for another language in Haskell, but I'm puzzled on how to approach this problem. I'm looking for an abstract and elegant representation of the language in Haskell, which is also useful for code generation. The language in question is InstallScript (link to the language reference guide). Could someone please provide hints (maybe with examples?) on how to capture the language constructs employed in InstallScript in Haskell types, or point to similar projects for inspiration?

도움이 되었습니까?

해결책

This is a classic problem to solve in Haskell.

  • Define a abstract syntax tree for your language
  • Define a pretty printer (to generate code)

For bonus points:

  • Define a parser
  • Write a nice Haskell combinator library to let you embed the target in Haskell
  • Write an optimizer for your abstract syntax

There are many, many examples on Hackage (e.g. this one).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top