Clinton
Clinton

Reputation: 23135

Template Haskell - Static Assert

I've written the following function:

staticAssert :: Bool -> Q [Dec]
staticAssert cond = case cond of
    True -> return []
    False -> fail "staticAssert failed"

Basically this evaluates condition at compile time and if it is false causes a compile error.

However, what I would like for staticAssert to instead of outputting "staticAssert failed", output the expression that failed the assertion.

Upvotes: 2

Views: 270

Answers (1)

Carl
Carl

Reputation: 27003

It looks like you want location from Language.Haskell.TH.

Upvotes: 2

Related Questions