Ticket #7256 (closed bug: fixed)

Opened 8 months ago

Last modified 6 months ago

Missing dataCast1 and dataCast2 methods in Data.Data instances

Reported by: dreixel Owned by:
Priority: normal Milestone: 7.8.1
Component: Compiler Version: 7.6.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Having a look at Data instances in module Data.Data, Ptr a and ForeignPtr a are missing a dataCast1 = gcast1 line. And Array a b seems to be missing the dataCast2 method.

Change History

  Changed 8 months ago by simonpj

  • difficulty set to Unknown

Any chance of a patch? Sounds as if you know just what to do.

  Changed 8 months ago by dreixel

Yes, I'll take care of this, it's trivial.

follow-up: ↓ 5   Changed 8 months ago by dreixel

  • status changed from new to infoneeded

Here's the fix:

diff --git a/Data/Data.hs b/Data/Data.hs
index 0a29668..cb2d894 100644
--- a/Data/Data.hs
+++ b/Data/Data.hs
@@ -1275,27 +1275,27 @@ instance (Data a, Data b, Data c, Data d, Data e, Data f
 
 ------------------------------------------------------------------------------
 
-instance Typeable a => Data (Ptr a) where
+instance (Data a, Typeable a) => Data (Ptr a) where
   toConstr _   = error "Data.Data.toConstr(Ptr)"
   gunfold _ _  = error "Data.Data.gunfold(Ptr)"
   dataTypeOf _ = mkNoRepType "GHC.Ptr.Ptr"
-
+  dataCast1 x  = gcast1 x
 
 ------------------------------------------------------------------------------
 
-instance Typeable a => Data (ForeignPtr a) where
+instance (Data a, Typeable a) => Data (ForeignPtr a) where
   toConstr _   = error "Data.Data.toConstr(ForeignPtr)"
   gunfold _ _  = error "Data.Data.gunfold(ForeignPtr)"
   dataTypeOf _ = mkNoRepType "GHC.ForeignPtr.ForeignPtr"
-
+  dataCast1 x  = gcast1 x
 
 ------------------------------------------------------------------------------
 -- The Data instance for Array preserves data abstraction at the cost of 
 -- inefficiency. We omit reflection services for the sake of data abstraction.
-instance (Typeable a, Data b, Ix a) => Data (Array a b)
+instance (Typeable a, Data a, Data b, Ix a) => Data (Array a b)
  where
   gfoldl f z a = z (listArray (bounds a)) `f` (elems a)
   toConstr _   = error "Data.Data.toConstr(Array)"
   gunfold _ _  = error "Data.Data.gunfold(Array)"
   dataTypeOf _ = mkNoRepType "Data.Array.Array"
-
+  dataCast2 x  = gcast2 x

Note however that this requires adding additional Data constraints to these instances; perhaps this is the reason why these methods were omitted in the first place. So fixing this might break client code that uses these instances. Nonetheless, they are required for the correct behavior of SYB's ext/1/2 functions.

Shall I go ahead and push the patch?

  Changed 7 months ago by igloo

  • status changed from infoneeded to patch

in reply to: ↑ 3   Changed 7 months ago by igloo

  • milestone set to 7.8.1

Replying to dreixel:

Shall I go ahead and push the patch?

Probably worth asking on libraries@, to give people the chance to object.

  Changed 6 months ago by igloo

  • owner dreixel deleted
  • status changed from patch to new

Removing patch tag until libraries@ has given an opinion.

  Changed 6 months ago by dreixel

There was no opinion:  http://permalink.gmane.org/gmane.comp.lang.haskell.libraries/18099

I was going to proceed and patch.

  Changed 6 months ago by igloo

  • status changed from new to closed
  • resolution set to fixed

Ah, great. I've applied it. Thanks!

Note: See TracTickets for help on using tickets.