[commit: ghc] master: Allow deriving Typeable for more tycons (92191a3)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[commit: ghc] master: Allow deriving Typeable for more tycons (92191a3)

Simon Peyton Jones
Pedro

Surely should be some user-manual change to go with this?  

Simon

| -----Original Message-----
| From: ghc-commits-bounces at haskell.org [mailto:ghc-commits-
| bounces at haskell.org] On Behalf Of Jos? Pedro Magalh?es
| Sent: 07 May 2013 13:27
| To: ghc-commits at haskell.org
| Subject: [commit: ghc] master: Allow deriving Typeable for more tycons
| (92191a3)
|
| Repository : http://darcs.haskell.org/ghc.git/
|
| On branch  : master
|
| https://github.com/ghc/ghc/commit/92191a39a59a036fde4de926e2e322a2c50c84
| cf
|
| >---------------------------------------------------------------
|
| commit 92191a39a59a036fde4de926e2e322a2c50c84cf
| Author: Jose Pedro Magalhaes <jpm at cs.ox.ac.uk>
| Date:   Tue May 7 09:16:29 2013 +0100
|
|     Allow deriving Typeable for more tycons
|
| >---------------------------------------------------------------
|
|  compiler/typecheck/TcDeriv.lhs | 3 ++-
|  1 file changed, 2 insertions(+), 1 deletion(-)
|
| diff --git a/compiler/typecheck/TcDeriv.lhs
| b/compiler/typecheck/TcDeriv.lhs index 7da30d19b..9b82ed6 100644
| --- a/compiler/typecheck/TcDeriv.lhs
| +++ b/compiler/typecheck/TcDeriv.lhs
| @@ -683,7 +683,8 @@ mkEqnHelp :: CtOrigin -> [TyVar] -> Class -> [Type]
| -> Type
|
|  mkEqnHelp orig tvs cls cls_tys tc_app mtheta
|    | Just (tycon, tc_args) <- tcSplitTyConApp_maybe tc_app
| -  , isAlgTyCon tycon    -- Check for functions, primitive types etc
| +  , className cls == typeableClassName || isAlgTyCon tycon
| +  -- Avoid functions, primitive types, etc, unless it's Typeable
|    = mk_alg_eqn tycon tc_args
|    | otherwise
|    = failWithTc (derivingThingErr False cls cls_tys tc_app
|
|
|
| _______________________________________________
| ghc-commits mailing list
| ghc-commits at haskell.org
| http://www.haskell.org/mailman/listinfo/ghc-commits


Reply | Threaded
Open this post in threaded view
|

[commit: ghc] master: Allow deriving Typeable for more tycons (92191a3)

José Pedro Magalhães
Hi Simon,

Yes. I still need to do some more work, though, because one thing is not
yet working as I would like it
to. Right now, if you define a datatype with -XDataKinds, you can derive
Typeable for the promoted
constructors:

data N = Z | S N deriving Typeable -- for N
> deriving instance Typeable Z
> deriving instance Typeable S
>

Note that the last two Typeable instances can only be given by standalone
deriving. However, in case
the user specifies -XAutoDeriveTypeable, I would expect all three instances
to be unnecessary. Right
now, however, we do not automatically derive Typeable instances for
promoted constructors. This is
because they are not tycl_decls (as in makeDerivSpecs in TcDeriv). What's
the best way to easily
get hold of all the promoted tycons in a module?


Thanks,
Pedro

On Wed, May 8, 2013 at 10:37 AM, Simon Peyton-Jones
<simonpj at microsoft.com>wrote:

> Pedro
>
> Surely should be some user-manual change to go with this?
>
> Simon
>
> | -----Original Message-----
> | From: ghc-commits-bounces at haskell.org [mailto:ghc-commits-
> | bounces at haskell.org] On Behalf Of Jos? Pedro Magalh?es
> | Sent: 07 May 2013 13:27
> | To: ghc-commits at haskell.org
> | Subject: [commit: ghc] master: Allow deriving Typeable for more tycons
> | (92191a3)
> |
> | Repository : http://darcs.haskell.org/ghc.git/
> |
> | On branch  : master
> |
> | https://github.com/ghc/ghc/commit/92191a39a59a036fde4de926e2e322a2c50c84
> | cf
> |
> | >---------------------------------------------------------------
> |
> | commit 92191a39a59a036fde4de926e2e322a2c50c84cf
> | Author: Jose Pedro Magalhaes <jpm at cs.ox.ac.uk>
> | Date:   Tue May 7 09:16:29 2013 +0100
> |
> |     Allow deriving Typeable for more tycons
> |
> | >---------------------------------------------------------------
> |
> |  compiler/typecheck/TcDeriv.lhs | 3 ++-
> |  1 file changed, 2 insertions(+), 1 deletion(-)
> |
> | diff --git a/compiler/typecheck/TcDeriv.lhs
> | b/compiler/typecheck/TcDeriv.lhs index 7da30d19b..9b82ed6 100644
> | --- a/compiler/typecheck/TcDeriv.lhs
> | +++ b/compiler/typecheck/TcDeriv.lhs
> | @@ -683,7 +683,8 @@ mkEqnHelp :: CtOrigin -> [TyVar] -> Class -> [Type]
> | -> Type
> |
> |  mkEqnHelp orig tvs cls cls_tys tc_app mtheta
> |    | Just (tycon, tc_args) <- tcSplitTyConApp_maybe tc_app
> | -  , isAlgTyCon tycon    -- Check for functions, primitive types etc
> | +  , className cls == typeableClassName || isAlgTyCon tycon
> | +  -- Avoid functions, primitive types, etc, unless it's Typeable
> |    = mk_alg_eqn tycon tc_args
> |    | otherwise
> |    = failWithTc (derivingThingErr False cls cls_tys tc_app
> |
> |
> |
> | _______________________________________________
> | ghc-commits mailing list
> | ghc-commits at haskell.org
> | http://www.haskell.org/mailman/listinfo/ghc-commits
>
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://www.haskell.org/mailman/listinfo/ghc-devs
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20130516/05895c94/attachment.htm>

Reply | Threaded
Open this post in threaded view
|

[commit: ghc] master: Allow deriving Typeable for more tycons (92191a3)

Simon Peyton Jones
Oh, it's easy.  If you know what TyCons are defined in this file (and you do, in derivTyDecl), then find the TyCon, and then do
          [ promoted_dc | Just promoted_dc <- map promoteDataCon_maybe (tyConDataCons tc) ]


Simon

Microsoft Research Limited (company number 03369488) is registered in England and Wales
Registered office 21 Station Road, Cambridge, CB1 2FB

From: josepedromagalhaes at gmail.com [mailto:josepedromagalhaes at gmail.com] On Behalf Of Jos? Pedro Magalh?es
Sent: 16 May 2013 10:34
To: Simon Peyton-Jones
Cc: ghc-devs at haskell.org
Subject: Re: [commit: ghc] master: Allow deriving Typeable for more tycons (92191a3)

Hi Simon,

Yes. I still need to do some more work, though, because one thing is not yet working as I would like it
to. Right now, if you define a datatype with -XDataKinds, you can derive Typeable for the promoted
constructors:
data N = Z | S N deriving Typeable -- for N
deriving instance Typeable Z
deriving instance Typeable S

Note that the last two Typeable instances can only be given by standalone deriving. However, in case
the user specifies -XAutoDeriveTypeable, I would expect all three instances to be unnecessary. Right
now, however, we do not automatically derive Typeable instances for promoted constructors. This is
because they are not tycl_decls (as in makeDerivSpecs in TcDeriv). What's the best way to easily
get hold of all the promoted tycons in a module?


Thanks,
Pedro
On Wed, May 8, 2013 at 10:37 AM, Simon Peyton-Jones <simonpj at microsoft.com<mailto:simonpj at microsoft.com>> wrote:
Pedro

Surely should be some user-manual change to go with this?

Simon

| -----Original Message-----
| From: ghc-commits-bounces at haskell.org<mailto:ghc-commits-bounces at haskell.org> [mailto:ghc-commits-<mailto:ghc-commits->
| bounces at haskell.org<mailto:bounces at haskell.org>] On Behalf Of Jos? Pedro Magalh?es
| Sent: 07 May 2013 13:27
| To: ghc-commits at haskell.org<mailto:ghc-commits at haskell.org>
| Subject: [commit: ghc] master: Allow deriving Typeable for more tycons
| (92191a3)
|
| Repository : http://darcs.haskell.org/ghc.git/
|
| On branch  : master
|
| https://github.com/ghc/ghc/commit/92191a39a59a036fde4de926e2e322a2c50c84
| cf
|
| >---------------------------------------------------------------
|
| commit 92191a39a59a036fde4de926e2e322a2c50c84cf
| Author: Jose Pedro Magalhaes <jpm at cs.ox.ac.uk<mailto:jpm at cs.ox.ac.uk>>
| Date:   Tue May 7 09:16:29 2013 +0100
|
|     Allow deriving Typeable for more tycons
|
| >---------------------------------------------------------------
|
|  compiler/typecheck/TcDeriv.lhs | 3 ++-
|  1 file changed, 2 insertions(+), 1 deletion(-)
|
| diff --git a/compiler/typecheck/TcDeriv.lhs
| b/compiler/typecheck/TcDeriv.lhs index 7da30d19b..9b82ed6 100644
| --- a/compiler/typecheck/TcDeriv.lhs
| +++ b/compiler/typecheck/TcDeriv.lhs
| @@ -683,7 +683,8 @@ mkEqnHelp :: CtOrigin -> [TyVar] -> Class -> [Type]
| -> Type
|
|  mkEqnHelp orig tvs cls cls_tys tc_app mtheta
|    | Just (tycon, tc_args) <- tcSplitTyConApp_maybe tc_app
| -  , isAlgTyCon tycon    -- Check for functions, primitive types etc
| +  , className cls == typeableClassName || isAlgTyCon tycon
| +  -- Avoid functions, primitive types, etc, unless it's Typeable
|    = mk_alg_eqn tycon tc_args
|    | otherwise
|    = failWithTc (derivingThingErr False cls cls_tys tc_app
|
|
|
| _______________________________________________
| ghc-commits mailing list
| ghc-commits at haskell.org<mailto:ghc-commits at haskell.org>
| http://www.haskell.org/mailman/listinfo/ghc-commits
_______________________________________________
ghc-devs mailing list
ghc-devs at haskell.org<mailto:ghc-devs at haskell.org>
http://www.haskell.org/mailman/listinfo/ghc-devs

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20130516/3c38c014/attachment.htm>

Reply | Threaded
Open this post in threaded view
|

[commit: ghc] master: Allow deriving Typeable for more tycons (92191a3)

José Pedro Magalhães
Ok, done now.


Cheers,
Pedro

On Thu, May 16, 2013 at 5:26 PM, Simon Peyton-Jones
<simonpj at microsoft.com>wrote:

>  Oh, it?s easy.  If you know what TyCons are defined in this file (and
> you do, in derivTyDecl), then find the TyCon, and then do****
>
>           [ promoted_dc | Just promoted_dc <- map promoteDataCon_maybe
> (tyConDataCons tc) ]****
>
> ** **
>
> ** **
>
> Simon****
>
> * *
>
> *Microsoft Research Limited (company number 03369488) is registered in
> England and Wales*
>
> *Registered office 21 Station Road, Cambridge, CB1 2FB ***
>
> ** **
>
> *From:* josepedromagalhaes at gmail.com [mailto:josepedromagalhaes at gmail.com]
> *On Behalf Of *Jos? Pedro Magalh?es
> *Sent:* 16 May 2013 10:34
> *To:* Simon Peyton-Jones
> *Cc:* ghc-devs at haskell.org
> *Subject:* Re: [commit: ghc] master: Allow deriving Typeable for more
> tycons (92191a3)****
>
> ** **
>
> Hi Simon,
>
> Yes. I still need to do some more work, though, because one thing is not
> yet working as I would like it
> to. Right now, if you define a datatype with -XDataKinds, you can derive
> Typeable for the promoted
> constructors:****
>
> data N = Z | S N deriving Typeable -- for N
> deriving instance Typeable Z
> deriving instance Typeable S****
>
>
> Note that the last two Typeable instances can only be given by standalone
> deriving. However, in case
> the user specifies -XAutoDeriveTypeable, I would expect all three
> instances to be unnecessary. Right
> now, however, we do not automatically derive Typeable instances for
> promoted constructors. This is
> because they are not tycl_decls (as in makeDerivSpecs in TcDeriv). What's
> the best way to easily
> get hold of all the promoted tycons in a module?
>
>
> Thanks,
> Pedro****
>
> On Wed, May 8, 2013 at 10:37 AM, Simon Peyton-Jones <simonpj at microsoft.com>
> wrote:****
>
> Pedro
>
> Surely should be some user-manual change to go with this?
>
> Simon****
>
>
> | -----Original Message-----
> | From: ghc-commits-bounces at haskell.org [mailto:ghc-commits-
> | bounces at haskell.org] On Behalf Of Jos? Pedro Magalh?es
> | Sent: 07 May 2013 13:27
> | To: ghc-commits at haskell.org
> | Subject: [commit: ghc] master: Allow deriving Typeable for more tycons
> | (92191a3)
> |
> | Repository : http://darcs.haskell.org/ghc.git/
> |
> | On branch  : master
> |
> | https://github.com/ghc/ghc/commit/92191a39a59a036fde4de926e2e322a2c50c84
> | cf
> |
> | >---------------------------------------------------------------
> |
> | commit 92191a39a59a036fde4de926e2e322a2c50c84cf
> | Author: Jose Pedro Magalhaes <jpm at cs.ox.ac.uk>
> | Date:   Tue May 7 09:16:29 2013 +0100
> |
> |     Allow deriving Typeable for more tycons
> |
> | >---------------------------------------------------------------
> |
> |  compiler/typecheck/TcDeriv.lhs | 3 ++-
> |  1 file changed, 2 insertions(+), 1 deletion(-)
> |
> | diff --git a/compiler/typecheck/TcDeriv.lhs
> | b/compiler/typecheck/TcDeriv.lhs index 7da30d19b..9b82ed6 100644
> | --- a/compiler/typecheck/TcDeriv.lhs
> | +++ b/compiler/typecheck/TcDeriv.lhs
> | @@ -683,7 +683,8 @@ mkEqnHelp :: CtOrigin -> [TyVar] -> Class -> [Type]
> | -> Type
> |
> |  mkEqnHelp orig tvs cls cls_tys tc_app mtheta
> |    | Just (tycon, tc_args) <- tcSplitTyConApp_maybe tc_app
> | -  , isAlgTyCon tycon    -- Check for functions, primitive types etc
> | +  , className cls == typeableClassName || isAlgTyCon tycon
> | +  -- Avoid functions, primitive types, etc, unless it's Typeable
> |    = mk_alg_eqn tycon tc_args
> |    | otherwise
> |    = failWithTc (derivingThingErr False cls cls_tys tc_app
> |
> |
> |
> | _______________________________________________
> | ghc-commits mailing list
> | ghc-commits at haskell.org
> | http://www.haskell.org/mailman/listinfo/ghc-commits****
>
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://www.haskell.org/mailman/listinfo/ghc-devs****
>
> ** **
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20130521/f353cbb8/attachment.htm>