Newtype deriving doesn't work with type families
This assumes -XTypeFamiles -XGeneralizedNewtypeDeriving
. Example:
class C a where
type T a
foo :: a -> T a
instance C Int where
type T Int = Int
foo = id
newtype N = N Int deriving(C)
This happily produces an instance C N
but no type instance T N
. It should either (preferably) generate
type instance T N = Int
or fail. The example also compiles if T
is a data family (the Int
instance needs to be change accordingly). It should probably fail in this case.
BTW, this also compiles fine, with rather dramatic consequences:
type family T a
class C a where
foo :: a -> T a
type instance T Int = Int
instance C Int where
foo = id
type instance T N = Double
newtype N = N Int deriving(C)
I guess this last example is the same bug as #1496 (closed). I wonder if the deriving clause could generate something like:
instance T Int ~ T N => C Int
- Show closed items
Relates to
Activity
-
Newest first Oldest first
-
Show all activity Show comments only Show history only
- Simon Peyton Jones mentioned in issue #1496 (closed)
mentioned in issue #1496 (closed)
- rl@cse.unsw.edu.au changed weight to 5
changed weight to 5
- rl@cse.unsw.edu.au added Tbug Trac import labels
added Tbug Trac import labels
- Ian Lynagh <igloo@earth.li> changed milestone to %6.10.2
changed milestone to %6.10.2
- Simon Peyton Jones changed the description
changed the description
- Developer
Good point. For now I'm just going to make it fail. It's quite a bit more work to make it generate the extra instance, and the fact that it does not work at all for 'data' convinced me.
It's annoying that you therefore cannot do newtype-deriving for a class with an associated type. An alternative is to allow top-level declarations for associated types, and check that these exist when doing the instance decl. So this would be valid:
class C a where type T a op :: a -> T a type instance T Int = Bool instance C Int where op x = True
So I'll leave this open to record the idea, but meanwhile I'll push a patch to make it fail uniformly.
Simon
Trac metadata
Trac field Value Test case → deriving/should_fail/T2721 - Simon Peyton Jones mentioned in commit 3de678a0
mentioned in commit 3de678a0
- Ben Gamari mentioned in commit 24a5fdb5
mentioned in commit 24a5fdb5
- Simon Peyton Jones assigned to @trac-igloo
assigned to @trac-igloo
- Developer
This is the patch
Wed Dec 31 16:43:00 GMT 2008 simonpj@microsoft.com * Fix Trac #2721: reject newtype deriving if the class has associated types
Pls merge; then leave the ticket open as feature request for 6.12
Simon
Trac metadata
Trac field Value Type Bug → MergeReq - Simon Peyton Jones added backport label and removed Tbug label
- Ian Lynagh <igloo@earth.li> changed milestone to %6.12 branch
changed milestone to %6.12 branch
Merged.
Trac metadata
Trac field Value Type MergeReq → FeatureRequest - Ian Lynagh <igloo@earth.li> added Tfeature request label and removed backport label
added Tfeature request label and removed backport label
- Ian Lynagh <igloo@earth.li> unassigned @trac-igloo
unassigned @trac-igloo
Trac metadata
Trac field Value CC → tom.schrijvers@cs.kuleuven.be - Ian Lynagh <igloo@earth.li> changed milestone to %6.12.3
changed milestone to %6.12.3
- Ian Lynagh <igloo@earth.li> removed milestone
removed milestone
- Ian Lynagh <igloo@earth.li> changed weight to 3
changed weight to 3
Trac metadata
Trac field Value Priority normal → low - Ian Lynagh <igloo@earth.li> changed milestone to %7.0.2
changed milestone to %7.0.2
- Ian Lynagh <igloo@earth.li> changed milestone to %7.2.1
changed milestone to %7.2.1
Trac metadata
Trac field Value TypeOfFailure - → OtherFailure - Ian Lynagh <igloo@earth.li> changed milestone to %7.4.1
changed milestone to %7.4.1
- Ian Lynagh <igloo@earth.li> changed milestone to %7.6.1
changed milestone to %7.6.1
- Ian Lynagh <igloo@earth.li> changed weight to 0
changed weight to 0
Trac metadata
Trac field Value Priority low → lowest - rl@cse.unsw.edu.au mentioned in issue #6147 (closed)
mentioned in issue #6147 (closed)
- Ryan Scott mentioned in issue #7204
mentioned in issue #7204
- Ian Lynagh <igloo@earth.li> changed milestone to %7.6.2
changed milestone to %7.6.2
- Ryan Scott mentioned in issue #8165 (closed)
mentioned in issue #8165 (closed)
- thoughtpolice changed milestone to %7.10.1
changed milestone to %7.10.1
Moving to 7.10.1.
Trac metadata
Trac field Value Component Compiler → Compiler (Type checker) - thoughtpolice removed milestone
removed milestone
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.
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.
- thoughtpolice changed milestone to %8.0.1
changed milestone to %8.0.1
Milestone renamed
- Maintainer
Trac metadata
Trac field Value Related - → #8165 (closed) - Ryan Scott changed milestone to %8.2.1
changed milestone to %8.2.1
- Maintainer
Trac metadata
Trac field Value Differential revisions - → D2636 - Ryan Scott mentioned in issue #12810 (closed)
mentioned in issue #12810 (closed)
- Ryan Scott mentioned in commit 630d8817
mentioned in commit 630d8817
- Ryan Scott closed
closed
- Maintainer
Trac metadata
Trac field Value Resolution Unresolved → ResolvedFixed - Ryan Scott mentioned in issue #13404 (closed)
mentioned in issue #13404 (closed)
- Ryan Scott mentioned in issue #13758 (closed)
mentioned in issue #13758 (closed)
- Ryan Scott added deriving label
added deriving label
- trac-import added Tbug label
added Tbug label
- Ben Gamari added Plow label
added Plow label
- Ryan Scott mentioned in merge request !7113 (closed)
mentioned in merge request !7113 (closed)