gatoatigrado
gatoatigrado

Reputation: 16850

Haskell -- how to use the new 4-argument quasi quoter

It looks like the quasi quoter syntax has changed to now accept 4 arguments [ link ]. Has anyone used it yet? Thanks. I just want to build something really really simple, and the examples on the web won't work now.

Thanks in advance.

Upvotes: 3

Views: 340

Answers (2)

C. A. McCann
C. A. McCann

Reputation: 77374

Each piece of the QuasiQuoter is just a function that takes a string (the content of the quasi-quote) and returns an appropriate value in the Q monad. If your quasiquoter doesn't support being used in some of those contexts, just return an error, e.g.:

someQuoter = QuasiQuoter { quoteType = const $ fail "type context unsupported" 
                         , -- etc ...
                         }

The fail method calls report True, which produces a compiler error. This is pretty much the correct behavior.

Upvotes: 3

porges
porges

Reputation: 30580

Basically the changes are that you can now make quasiquoters for types and declarations (in addition to expressions and patterns).

It should be fine to set the type/declaration fields to error "This quasiquoter doesn't support splicing types/declarations" if you don't want to use them.

Upvotes: 2

Related Questions