haskell 代码中包含的 cpp 语句不起作用

The cpp statements included in the haskell code don't work

我在 Haskell 中使用 {-# LANGUAGE CPP #-} pragma,然而,haskell 代码中包含的 cpp 语句对我不起作用:当我 运行 堆栈安装时,编译器给我以下错误:

error: parse error on input '#'.

有什么建议吗?

这是我在 GHC 8.4.3 版中使用的代码示例:

{-# LANGUAGE CPP #-}
  ...
  #if MIN_VERSION_base(4,9,0)
  import Data.Functor.Classes
  #endif

代码 haskell 中的 cpp 语句必须不缩进。

In my case, while the Haskell code indentation was correct, the c++ statement within the Haskell code must be unindented.

我只是将代码行从 cpp 缩进为零。 Haskell 代码的其余部分保持不变。

代码更正:

{-# LANGUAGE CPP #-}
  ...
#if MIN_VERSION_base(4,9,0)
  import Data.Functor.Classes
  ...
#endif

此致。