Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GHC can't infer unlifted kind

I'm running up against what looks like invalid code generated by Happy. The problem boils down to GHC not inferring a polykinded type signature for a function. Here is an example of this:

{-# Language MagicHash #-}

f x = ()

main = pure (f 1#)

Since GHC is inferring f :: a -> () where a :: *, this fails with

 • 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#)

Are there any language pragmas I could just turn on to get this code to compile? I know I could in theory just add type signatures but, as this is code generated by Happy which I'd prefer not to have to manually modify anything.

like image 930
Alec Avatar asked Oct 30 '22 04:10

Alec


1 Answers

As hinted at by @dfeuer, this is impossible. In the worst case, GHC would have to look for usages of a given function across the whole project in order to infer the levity of an argument.

This was reported as a bug in Happy and has since been fixed.

like image 96
Alec Avatar answered Nov 15 '22 08:11

Alec