Opened 6 years ago

Closed 2 years ago

#7459 closed feature request (fixed)

deriving Generic does not work with TypeLits

Reported by: maxtaldykin Owned by: dreixel
Priority: normal Milestone:
Component: Compiler Version: 7.6.1
Keywords: Generics Cc: nathanhowell@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Other Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

{-# LANGUAGE DataKinds, KindSignatures #-}
{-# LANGUAGE DeriveGeneric #-}

import GHC.TypeLits
import GHC.Generics

data F (a :: Symbol)
data X = X (F "hello") deriving Generic

Trying to derive Generics instance for simple datatype with Symbol inside but GHC complains:

  Can't make a derived instance of `Generic X':
     X must not have unlifted or polymorphic arguments
   In the data declaration for `X'

I found that this could be fixed by adding single line to isTauTy:

--- a/compiler/typecheck/TcType.lhs
+++ b/compiler/typecheck/TcType.lhs
@@ -899,6 +899,7 @@ mkTcEqPred ty1 ty2
 isTauTy :: Type -> Bool
 isTauTy ty | Just ty' <- tcView ty = isTauTy ty'
 isTauTy (TyVarTy _)      = True
+isTauTy (LitTy _)        = True
 isTauTy (TyConApp tc tys) = all isTauTy tys && isTauTyCon tc
 isTauTy (AppTy a b)      = isTauTy a && isTauTy b
 isTauTy (FunTy a b)      = isTauTy a && isTauTy b

Change History (11)

comment:1 Changed 6 years ago by dreixel

Owner: set to dreixel
Type: bugfeature request
Type of failure: GHC rejects valid programOther

Thanks for the report, although I don't think this is a bug. We have not intended Generic to be used with TypeLits (or any DataKinds stuff); the error message is not entirely accurate, but that's not what you are reporting.

Changing isTauTy might have deep implications throughout the compiler; I don't think that's the right "fix" here. I would be more inclined to change bad_arg_type in TcGenGenerics. But first we should think exactly of what generic programming with arguments of kind Symbol implies. Can you tell me what kind of generic functionality you want on datatypes such as F and X? Just some example values and the functions you would want to use on them would be clarifying.

comment:2 Changed 6 years ago by simonpj

difficulty: Unknown

I don't know abou the generic part, but it's certainly the case that isTauTy should return True for LitTy. I'll change that, but meanwhile I'll leave this ticket open because it's not clear what the behaviour of generics should be on LitTy.

Simon

comment:3 Changed 6 years ago by simonpj@…

commit 61f770f6df66e75c8920c17840670bea971062bf

Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Sat Dec 1 18:29:21 2012 +0000

    isTauTy should be True for LitTy (see Trac #7459)

 compiler/typecheck/TcType.lhs |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

comment:4 Changed 6 years ago by nathanhowell

Cc: nathanhowell@… added

comment:5 Changed 5 years ago by igloo

Milestone: 7.8.1

comment:6 Changed 4 years ago by thoughtpolice

Milestone: 7.8.37.10.1

Moving to 7.10.1

comment:7 Changed 4 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:8 Changed 3 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

comment:9 Changed 3 years ago by simonpj

Keywords: Generics added

comment:10 Changed 3 years ago by thomie

Milestone: 8.0.1

comment:11 Changed 2 years ago by RyanGlScott

Resolution: fixed
Status: newclosed

#10604 provides a couple of motivating examples for why generic programming over data-kinded types would be useful. Furthermore, the original bug in this ticket has long since been fixed, and I think it's clear by now that generics shouldn't be needlessly kind-restricted. Closing.

Note: See TracTickets for help on using tickets.