import Data.Void (Void,absurd)
Let's say I have a little language of terms:
data Term cv where Var :: v -> Term cv Con :: c -> [Term cv] -> Term cv
If I want to combine terms like Term c Void and Term c Int , this should be possible, since I have a guarantee that the first member does not contain any variables. So I can write a function:
castVar :: Term c Void -> Term cv castVar (Var i ) = absurd i castVar (Con x xs) = Con x (map castVar xs)
However, it would be a shame to actually run this function, since I know that nothing really changes. Is it possible to add the following pragmas:
{-# NOINLINE castVar #-} {-# RULES "castVar/id" forall x. castVar x = x; #-}
And will it really achieve the desired result?
Are there any better ways to do this?
source share