Coming from C++, I'm used to be able to build simple forms of compile-time assertions, where I could emit warnings or errors during compilation if some simple conditions (e.g. over simple algebraic expressions) weren't met via use of template meta-programming and/or cpp(1)
For instance, if I wanted to make sure my program compiles only when Int
has at least a certain minBound
/maxBound
range or alternatively, if a loss-free (as in reversible) conversion from Int64
to Int
is possible with the current compilation target. Is this possible with some GHC Haskell extension? My first guess would have been to use TH. Are there other GHC facilities that could be exploited to this end?
Int64
fits into anInt
at compile-time? – hvrInt lo hi
type whenlo
andhi
are bounds on the integer. Now, eg.(+)
has typeInt l1 h1 -> Int l2 h2 -> Int (l1 + l2) (h1 + h2)
. – Alexandre C.minBound/maxBound
check you can also use aconfigure
script. – Mikhail Glushenkov-XCPP
flag (or{-# LANGUAGE CPP #-}
directive). – Antal Spector-Zabusky