Fwd: [GHC] #7704: Phantom types break new polykind Typeable with either StandaloneDeriving or AutoDeriveTypeable
Hi Simon, How should an instance of Typeable for a polykinded tycon look like? E.g. if we have data Proxy (a :: k) = Proxy -- Proxy :: forall (k :: BOX). k -> * I suppose we want an instance forall k. instance Typeable (k -> *) (Proxy k) Right? So the universally quantified kind variables of the tycon should end up universally quantified in the instance as well. How does this translate to the ds_tvs, ds_tys, and ds_tc_args arguments of a DerivSpec?... Thanks, Pedro ---------- Forwarded message ---------- From: GHC <cvs-ghc@haskell.org> Date: Mon, Feb 18, 2013 at 8:42 PM Subject: [GHC] #7704: Phantom types break new polykind Typeable with either StandaloneDeriving or AutoDeriveTypeable To: Cc: ghc-tickets@haskell.org #7704: Phantom types break new polykind Typeable with either StandaloneDeriving or AutoDeriveTypeable -----------------------------+---------------------------------------------- Reporter: nwf | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.7 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Blockedby: Blocking: | Related: -----------------------------+---------------------------------------------- This test program, reduced from an attempt to bring ekmett's tagged package to HEAD, {{{ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE AutoDeriveTypeable #-} newtype Tagged s b = Tagged { unTagged :: b } }}} results in {{{ GHCi, version 7.7.20130218: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( typeable.hs, interpreted ) typeable.hs:5:1: Derived typeable instance must be of form (Typeable Tagged) In the stand-alone deriving instance for `Data.Typeable.Internal.Typeable Tagged' }}} This message is also emitted if I replace `AutoDeriveTypeable` `StandaloneDeriving` and `deriving instance Typeable Tagged`. However, a "deriving (Typeable)" clause on the newtype definition works just fine. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7704> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ ghc-tickets mailing list ghc-tickets@haskell.org http://www.haskell.org/mailman/listinfo/ghc-tickets
I suppose we want an instance forall k. instance Typeable (k -> *) (Proxy k) Yes, that looks right. So the universally quantified kind variables of the tycon should end up universally quantified in the instance as well. How does this translate to the ds_tvs, ds_tys, and ds_tc_args arguments of a DerivSpec My instinct is that the ds_tvs include both type and kind variables, kind variables first. The kinds of the type variables can mention the kind variables. The ds_tys field shoud include kind arguments as well as type arguments. Does that work? Simon From: josepedromagalhaes@gmail.com [mailto:josepedromagalhaes@gmail.com] On Behalf Of José Pedro Magalhães Sent: 19 February 2013 10:04 To: ghc-devs@haskell.org; Simon Peyton-Jones Subject: Fwd: [GHC] #7704: Phantom types break new polykind Typeable with either StandaloneDeriving or AutoDeriveTypeable Hi Simon, How should an instance of Typeable for a polykinded tycon look like? E.g. if we have data Proxy (a :: k) = Proxy -- Proxy :: forall (k :: BOX). k -> * I suppose we want an instance forall k. instance Typeable (k -> *) (Proxy k) Right? So the universally quantified kind variables of the tycon should end up universally quantified in the instance as well. How does this translate to the ds_tvs, ds_tys, and ds_tc_args arguments of a DerivSpec?... Thanks, Pedro ---------- Forwarded message ---------- From: GHC <cvs-ghc@haskell.org<mailto:cvs-ghc@haskell.org>> Date: Mon, Feb 18, 2013 at 8:42 PM Subject: [GHC] #7704: Phantom types break new polykind Typeable with either StandaloneDeriving or AutoDeriveTypeable To: Cc: ghc-tickets@haskell.org<mailto:ghc-tickets@haskell.org> #7704: Phantom types break new polykind Typeable with either StandaloneDeriving or AutoDeriveTypeable -----------------------------+---------------------------------------------- Reporter: nwf | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.7 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Blockedby: Blocking: | Related: -----------------------------+---------------------------------------------- This test program, reduced from an attempt to bring ekmett's tagged package to HEAD, {{{ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE AutoDeriveTypeable #-} newtype Tagged s b = Tagged { unTagged :: b } }}} results in {{{ GHCi, version 7.7.20130218: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( typeable.hs, interpreted ) typeable.hs:5:1: Derived typeable instance must be of form (Typeable Tagged) In the stand-alone deriving instance for `Data.Typeable.Internal.Typeable Tagged' }}} This message is also emitted if I replace `AutoDeriveTypeable` `StandaloneDeriving` and `deriving instance Typeable Tagged`. However, a "deriving (Typeable)" clause on the newtype definition works just fine. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7704> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ ghc-tickets mailing list ghc-tickets@haskell.org<mailto:ghc-tickets@haskell.org> http://www.haskell.org/mailman/listinfo/ghc-tickets
On Mon, Feb 25, 2013 at 4:11 PM, Simon Peyton-Jones <simonpj@microsoft.com>wrote:
I suppose we want an instance forall k. instance Typeable (k -> *) (Proxy k)
****
Yes, that looks right.****
** **
So the universally quantified kind variables of the tycon should end up universally quantified in the instance as well. How does this translate to the ds_tvs, ds_tys, and ds_tc_args arguments of a DerivSpec****
** **
My instinct is that the ds_tvs include both type and kind variables, kind variables first. The kinds of the type variables can mention the kind variables.
We don't have any type variables, we want to drop those, as we'll get those instances via the `(Typeable f, Typeable a) => Typeable (f a)` instance. In my branch, I currently get standalone deriving to give me the following for this example (tc-trace): Standalone deriving; tvs: [k] theta: [] cls: Typeable tys: [k -> *, Proxy k] Standalone deriving: class: Typeable class types: [k -> *] type: Proxy k This looks good to me. However, the generated instance is not what I think it should be (ddump-types): instance Typeable (forall (k :: BOX). k -> *) (Proxy k) The forall should be outside, as now the `k` in `Proxy k` is out of scope. I just don't know how to craft such a DerivSpec... what I have now is: DS { ds_loc = loc, ds_orig = orig, ds_name = dfun_name, ds_tvs = tvs , ds_cls = cls, ds_tys = tyConKind tycon : [mkTyConApp tycon tc_args] , ds_tc = tycon, ds_tc_args = tc_args , ds_theta = mtheta `orElse` [], ds_newtype = False }) } (I filter the type variables from the tc_args before this stage, leaving only kind variables.) Cheers, Pedro
participants (2)
-
José Pedro Magalhães -
Simon Peyton-Jones