Hello, community. Based on my online research, I think I have a solution for printing a Haskell expression. I tried to use this code:
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -pgmP cpp #-}
#define PRINT_EXP(x) (putStr #x >> putStr " = " >> print (x))
main = PRINT_EXP(null [1,2,3])
to produce this output:
"null [1,2,3]"
However, I get the following error:
/Users/detach/Dropbox/vsc-files/Haskell/HaskellMetaTest/app/Main.hs:1:1: error:
`cpp' failed in phase `C pre-processor'. (Exit code: 1)
|
1 | {-# LANGUAGE CPP #-}
| ^
*** Exception: ExitFailure 1
Apparently, this pragma fails:
{-# OPTIONS_GHC -pgmP cpp #-}
I have two questions:
- How can I solve this issue ?
- Whatâs the â#â symbol purpose in front of âxâ variable ? Does it have to do with C pre-processor ?
Thank you for any assistance.