Skip to content

TH Stage restriction check skips class method?

I was, as usual, abusing GHC, when I discovered some misbehavior.

{-# LANGUAGE RankNTypes, ExistentialQuantification, ConstraintKinds, AllowAmbiguousTypes #-}

module QuickCheckTH where

import Language.Haskell.TH

quickCheckTH :: forall arrow. (forall t a b. arrow t => t a b) -> Q [Dec]
quickCheckTH _ = do
  return []
{-# LANGUAGE TemplateHaskell, TypeApplications #-}

module BinaryEffects where

import QuickCheckTH

class A t where
  blah    :: t a b

$(quickCheckTH @A blah)

This should not be allowed, because blah is spliced in the same module where it is defined. When I run GHC in single-shot mode:

rae:15:25:26 ~/temp> ghc -c QuickCheckTH.hs
rae:15:27:05 ~/temp> ghc -c paper.hs
Bad interface file: paper.hi
    paper.hi: openBinaryFile: does not exist (No such file or directory)

Oops. Batch mode gives a different error:

rae:15:27:07 ~/temp> ghc paper.hs
Loaded package environment from /Users/rae/.ghc/x86_64-darwin-8.8.1/environments/default
[2 of 2] Compiling BinaryEffects    ( paper.hs, paper.o )
attempting to use module ‘main:BinaryEffects’ (paper.hs) which is not loaded
rae:15:27:51 ~/temp> 

Oops again.

The weird higher-ranky bit seems necessary.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information