is there a way to run tests at compile time using TH

I'd like to have code not compile if it doesn't pass the tests. Is there a way to use TH to generate compiler errors if the tests don't pass? -Alex-

Alex Jacobson
I'd like to have code not compile if it doesn't pass the tests.
Is there a way to use TH to generate compiler errors if the tests don't pass?
What about something like this? import Language.Haskell.TH import Tests -- this should export "testsPass :: Bool" -- don't bother trying to call this function. check = $( if testsPass then [| () |] else error "test failed" ) main = print "hi" If testsPass returns False, the compiler will throw an exception during compilation, like this: Exception when trying to run compile-time code: test failed [...]

On Sun, Aug 26, 2007 at 01:20:52AM -0700, Alex Jacobson wrote:
I'd like to have code not compile if it doesn't pass the tests.
Is there a way to use TH to generate compiler errors if the tests don't pass?
This should do it, in a different module to that which defines runtests: $( case runtests of Success -> return [] Failure -> error "Tests failed" ) Thanks Ian
participants (3)
-
Alex Jacobson
-
Chris Mears
-
Ian Lynagh