Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TH derivation doesn't work when the type name is qualified #22

Open
neongreen opened this issue Apr 3, 2017 · 1 comment
Open

TH derivation doesn't work when the type name is qualified #22

neongreen opened this issue Apr 3, 2017 · 1 comment

Comments

@neongreen
Copy link

Let's try to derive Arbitrary for Maybe, but imported qualified from Prelude:

{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TemplateHaskell   #-}

import           Data.DeriveTH   (derive, makeArbitrary)
import qualified Prelude         as P

import           Test.QuickCheck (Arbitrary (..))

derive makeArbitrary ''P.Maybe

It won't work:

    Not in scope: type constructor or class ‘Maybe’
    Perhaps you meant ‘P.Maybe’ (imported from Prelude)
    Not in scope: type constructor or class ‘Int’
    Perhaps you meant ‘P.Int’ (imported from Prelude)

When I run GHC with -ddump-splices, I see that derive generates the following code (which doesn't include qualified names):

    derive makeArbitrary ''P.Maybe
  ======>
    instance Arbitrary a_3530822107858468866 =>
             Arbitrary (Maybe a_3530822107858468866) where
      arbitrary
        = do { x <- choose (0 :: Int, 1);
               case x of {
                 0 -> return Nothing
                 1 -> do { x1 <- arbitrary;
                           return (Just x1) }
                 _ -> error "FATAL ERROR: Arbitrary instance, logic bug" } }
@ndmitchell
Copy link
Owner

Yep, agreed, that's a bug - but potentially a quite large one to fix. As per #6 I'm seeking to pass maintainership on to someone else, so it may be a while before anyone takes a proper look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants