GHC 无法推断未提升的种类

GHC can't infer unlifted kind

我 运行 遇到 Happy 生成的无效代码。问题归结为 GHC 没有为函数推断多类型签名。这是一个例子:

{-# Language MagicHash #-}

f x = ()

main = pure (f 1#)

由于 GHC 正在推断 f :: a -> () 其中 a :: *,因此失败

 • Couldn't match a lifted type with an unlifted type
   When matching the kind of ‘GHC.Prim.Int#’
 • In the first argument of ‘f’, namely ‘1#’
   In the first argument of ‘pure’, namely ‘(f 1#)’
   In the expression: pure (f 1#)

是否有任何我可以打开的语言编译指示来编译此代码?我知道理论上我可以只添加类型签名,但是,因为这是 Happy 生成的代码,我不想手动修改任何东西。

正如@dfeuer 所暗示的,这是不可能的。在最坏的情况下,GHC 将不得不在整个项目中寻找给定函数的用法,以推断出参数的重要性。

这被报告为 bug in Happy and has since been fixed