Volker Wysk | 5 Aug 18:41 2014
Picon

Old code broken by new Typeable class

Hi!

I've been working with GHC-4.6.3, and updating to GHC-4.8.3 breaks my code, 

because the Typeable class has been changed. The compiler produces this 

message:

---------

src/HsShellScript/ProcErr.chs:2294:4:

    ‘typeOf’ is not a (visible) method of class ‘Typeable’

---------

I want to define System.Posix.Process.ProcessStatus to be an instance of 

Typeable, so I can throw and catch it as an exception. ProcessStatus isn't 

typeable by default.

Is it still possible to make ProcessStatus a member of Typeable? How? 

Obviously, you can't accomplish it by deriving Typeable, because the definition 

can't be changed any longer.

This is the spot in question:

----------

import System.Posix.Process

import Data.Typeable

{-

data ProcessStatus = Exited ExitCode

                   | Terminated Signal

                   | Stopped Signal

                   deriving (Eq, Ord, Show)

-}

instance Typeable ProcessStatus where

   typeOf = const tyCon_ProcessStatus

tyCon_ProcessStatus = mkTyConApp (mkTyCon3 "hsshellscript"

                                           "HsShellScript.ProcErr"

                                           "Posix.ProcessStatus") []

instance Exception ProcessStatus

----------

Thanks,

V.W.

_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Carter Schonwald | 5 Aug 18:46 2014
Picon

Re: Old code broken by new Typeable class

i assume 7.6 and 7.8, if we're talking GHC rather than GCC :)

in 7.8 you can't define userland typeable instances, you need only write deriving (Typeable) and you're all set. 
add some CPP to select the instances suitable


On Tue, Aug 5, 2014 at 12:41 PM, Volker Wysk <verteiler <at> volker-wysk.de> wrote:

Hi!

I've been working with GHC-4.6.3, and updating to GHC-4.8.3 breaks my code, 

because the Typeable class has been changed. The compiler produces this 

message:

---------

src/HsShellScript/ProcErr.chs:2294:4:

    ‘typeOf’ is not a (visible) method of class ‘Typeable’

---------

I want to define System.Posix.Process.ProcessStatus to be an instance of 

Typeable, so I can throw and catch it as an exception. ProcessStatus isn't 

typeable by default.

Is it still possible to make ProcessStatus a member of Typeable? How? 

Obviously, you can't accomplish it by deriving Typeable, because the definition 

can't be changed any longer.

This is the spot in question:

----------

import System.Posix.Process

import Data.Typeable

{-

data ProcessStatus = Exited ExitCode

                   | Terminated Signal

                   | Stopped Signal

                   deriving (Eq, Ord, Show)

-}

instance Typeable ProcessStatus where

   typeOf = const tyCon_ProcessStatus

tyCon_ProcessStatus = mkTyConApp (mkTyCon3 "hsshellscript"

                                           "HsShellScript.ProcErr"

                                           "Posix.ProcessStatus") []

instance Exception ProcessStatus

----------

Thanks,

V.W.


_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Carter Schonwald | 5 Aug 18:49 2014
Picon

Re: Old code broken by new Typeable class

more concretely
#if defined(__GLASGOW_HASKELL__) && ( __GLASGOW_HASKELL__ >= 707)
 --- do the deriving version here
#else 
--- your current stuff
#endif


On Tue, Aug 5, 2014 at 12:46 PM, Carter Schonwald <carter.schonwald <at> gmail.com> wrote:
i assume 7.6 and 7.8, if we're talking GHC rather than GCC :)

in 7.8 you can't define userland typeable instances, you need only write deriving (Typeable) and you're all set. 
add some CPP to select the instances suitable


On Tue, Aug 5, 2014 at 12:41 PM, Volker Wysk <verteiler <at> volker-wysk.de> wrote:

Hi!

I've been working with GHC-4.6.3, and updating to GHC-4.8.3 breaks my code, 

because the Typeable class has been changed. The compiler produces this 

message:

---------

src/HsShellScript/ProcErr.chs:2294:4:

    ‘typeOf’ is not a (visible) method of class ‘Typeable’

---------

I want to define System.Posix.Process.ProcessStatus to be an instance of 

Typeable, so I can throw and catch it as an exception. ProcessStatus isn't 

typeable by default.

Is it still possible to make ProcessStatus a member of Typeable? How? 

Obviously, you can't accomplish it by deriving Typeable, because the definition 

can't be changed any longer.

This is the spot in question:

----------

import System.Posix.Process

import Data.Typeable

{-

data ProcessStatus = Exited ExitCode

                   | Terminated Signal

                   | Stopped Signal

                   deriving (Eq, Ord, Show)

-}

instance Typeable ProcessStatus where

   typeOf = const tyCon_ProcessStatus

tyCon_ProcessStatus = mkTyConApp (mkTyCon3 "hsshellscript"

                                           "HsShellScript.ProcErr"

                                           "Posix.ProcessStatus") []

instance Exception ProcessStatus

----------

Thanks,

V.W.


_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
adam vogt | 5 Aug 19:04 2014
Picon

Re: Old code broken by new Typeable class

Hi Volker,

You can use this extension:
http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#stand-alone-deriving
to write that orphan Typeable instance for most ghcs (probably 6.10 is
the earliest).

It might be worth pushing for a Typeable instance to be added to the
unix package (here:
http://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-Process.html#t:ProcessStatus,
with Carter's code): somebody else might define the same orphan
instance too, which will break programs that end up seeing both
instances.

Regards,
Adam

On Tue, Aug 5, 2014 at 12:49 PM, Carter Schonwald
<carter.schonwald <at> gmail.com> wrote:
> more concretely
> #if defined(__GLASGOW_HASKELL__) && ( __GLASGOW_HASKELL__ >= 707)
>  --- do the deriving version here
> #else
> --- your current stuff
> #endif
>
>
> On Tue, Aug 5, 2014 at 12:46 PM, Carter Schonwald
> <carter.schonwald <at> gmail.com> wrote:
>>
>> i assume 7.6 and 7.8, if we're talking GHC rather than GCC :)
>>
>> in 7.8 you can't define userland typeable instances, you need only write
>> deriving (Typeable) and you're all set.
>> add some CPP to select the instances suitable
>>
>>
>> On Tue, Aug 5, 2014 at 12:41 PM, Volker Wysk <verteiler <at> volker-wysk.de>
>> wrote:
>>>
>>> Hi!
>>>
>>> I've been working with GHC-4.6.3, and updating to GHC-4.8.3 breaks my
>>> code,
>>>
>>> because the Typeable class has been changed. The compiler produces this
>>>
>>> message:
>>>
>>> ---------
>>>
>>> src/HsShellScript/ProcErr.chs:2294:4:
>>>
>>>     ‘typeOf’ is not a (visible) method of class ‘Typeable’
>>>
>>> ---------
>>>
>>> I want to define System.Posix.Process.ProcessStatus to be an instance of
>>>
>>> Typeable, so I can throw and catch it as an exception. ProcessStatus
>>> isn't
>>>
>>> typeable by default.
>>>
>>> Is it still possible to make ProcessStatus a member of Typeable? How?
>>>
>>> Obviously, you can't accomplish it by deriving Typeable, because the
>>> definition
>>>
>>> can't be changed any longer.
>>>
>>> This is the spot in question:
>>>
>>> ----------
>>>
>>> import System.Posix.Process
>>>
>>> import Data.Typeable
>>>
>>> {-
>>>
>>> data ProcessStatus = Exited ExitCode
>>>
>>>                    | Terminated Signal
>>>
>>>                    | Stopped Signal
>>>
>>>                    deriving (Eq, Ord, Show)
>>>
>>> -}
>>>
>>> instance Typeable ProcessStatus where
>>>
>>>    typeOf = const tyCon_ProcessStatus
>>>
>>> tyCon_ProcessStatus = mkTyConApp (mkTyCon3 "hsshellscript"
>>>
>>>                                            "HsShellScript.ProcErr"
>>>
>>>                                            "Posix.ProcessStatus") []
>>>
>>> instance Exception ProcessStatus
>>>
>>> ----------
>>>
>>> Thanks,
>>>
>>> V.W.
>>>
>>>
>>> _______________________________________________
>>> Glasgow-haskell-users mailing list
>>> Glasgow-haskell-users <at> haskell.org
>>> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>>>
>>
>
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users <at> haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Volker Wysk | 5 Aug 19:51 2014
Picon

Re: Old code broken by new Typeable class

Am Dienstag, 5. August 2014, 12:49:29 schrieb Carter Schonwald:
> more concretely
> #if defined(__GLASGOW_HASKELL__) && ( __GLASGOW_HASKELL__ >= 707)
>  --- do the deriving version here

I can't do a deriving version, because ProcessStatus is part of the GHC 
libraries (System.Posix.Process). Its definition can't be changed.

> #else
> --- your current stuff
> #endif

Cheers,
V.W.
Volker Wysk | 5 Aug 19:47 2014
Picon

Re: Old code broken by new Typeable class

Am Dienstag, 5. August 2014, 12:46:23 schrieb Carter Schonwald:
> i assume 7.6 and 7.8, if we're talking GHC rather than GCC :)
> 
> in 7.8 you can't define userland typeable instances, you need only write
> deriving (Typeable) and you're all set.
> add some CPP to select the instances suitable

So you need to be able to change the definition of the data type, in order to 
add deriving (Typeable). It's not possible to add a Typeable instance 
declaration later.

When you can't change the definition, you're out of luck.

Okay,
V.W.
Brandon Allbery | 5 Aug 19:59 2014
Picon

Re: Old code broken by new Typeable class

On Tue, Aug 5, 2014 at 1:47 PM, Volker Wysk <verteiler <at> volker-wysk.de> wrote:
Am Dienstag, 5. August 2014, 12:46:23 schrieb Carter Schonwald:
> i assume 7.6 and 7.8, if we're talking GHC rather than GCC :)
>
> in 7.8 you can't define userland typeable instances, you need only write
> deriving (Typeable) and you're all set.
> add some CPP to select the instances suitable

So you need to be able to change the definition of the data type, in order to
add deriving (Typeable). It's not possible to add a Typeable instance
declaration later.

Are you sure? There is a standalone deriving syntax.

    deriving instance Typeable ProcessStatus


--
brandon s allbery kf8nh                               sine nomine associates
allbery.b <at> gmail.com                                  ballbery <at> sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Carter Schonwald | 5 Aug 20:03 2014
Picon

Re: Old code broken by new Typeable class

thats what i meant. I meant you can't WRITE the body of a typeable in 7.8, you can derive though


On Tue, Aug 5, 2014 at 1:59 PM, Brandon Allbery <allbery.b <at> gmail.com> wrote:
On Tue, Aug 5, 2014 at 1:47 PM, Volker Wysk <verteiler <at> volker-wysk.de> wrote:
Am Dienstag, 5. August 2014, 12:46:23 schrieb Carter Schonwald:
> i assume 7.6 and 7.8, if we're talking GHC rather than GCC :)
>
> in 7.8 you can't define userland typeable instances, you need only write
> deriving (Typeable) and you're all set.
> add some CPP to select the instances suitable

So you need to be able to change the definition of the data type, in order to
add deriving (Typeable). It's not possible to add a Typeable instance
declaration later.

Are you sure? There is a standalone deriving syntax.

    deriving instance Typeable ProcessStatus


--
brandon s allbery kf8nh                               sine nomine associates
allbery.b <at> gmail.com                                  ballbery <at> sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net

_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Volker Wysk | 5 Aug 20:33 2014
Picon

Re: Old code broken by new Typeable class

Am Dienstag, 5. August 2014, 13:59:26 schrieb Brandon Allbery:
> On Tue, Aug 5, 2014 at 1:47 PM, Volker Wysk <verteiler <at> volker-wysk.de>
> > So you need to be able to change the definition of the data type, in order
> > to
> > add deriving (Typeable). It's not possible to add a Typeable instance
> > declaration later.
> 
> Are you sure? There is a standalone deriving syntax.
> 
>     deriving instance Typeable ProcessStatus

Yes, that's the solution. 

You need these options for GHC: -XStandaloneDeriving -XDeriveDataTypeable

Thanks, and Bye,
V.W.
Edward Kmett | 5 Aug 21:29 2014
Picon

Re: Old code broken by new Typeable class

If you can't change the definition you can use the syntax Björn Bringert added back in 2006 or so for StandaloneDeriving.

Just turn on 

{-# LANGUAGE StandaloneDeriving, DeriveDataTypeable #-}

and then you can use

deriving instance Typeable Foo

-Edward


On Tue, Aug 5, 2014 at 1:47 PM, Volker Wysk <verteiler <at> volker-wysk.de> wrote:
Am Dienstag, 5. August 2014, 12:46:23 schrieb Carter Schonwald:
> i assume 7.6 and 7.8, if we're talking GHC rather than GCC :)
>
> in 7.8 you can't define userland typeable instances, you need only write
> deriving (Typeable) and you're all set.
> add some CPP to select the instances suitable

So you need to be able to change the definition of the data type, in order to
add deriving (Typeable). It's not possible to add a Typeable instance
declaration later.

When you can't change the definition, you're out of luck.

Okay,
V.W.
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Gmane