
#9112: support for deriving Vector/MVector instances -------------------------------------+------------------------------------ Reporter: jwlato | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by rwbarton): Replying to [comment:6 bitemyapp]:
I am trying to build hackage-server on Mac OS X with GHC 7.8 and I was told this ticket is relevant to my problems.
I've included the build error in this comment. [...]
These ''specific'' errors are easy to fix. `VecBase.MVector` (hereafter abbreviated `MVector`) is a standalone data family. There is an instance `MVector s Word32`, but no instance for the new type `MVector s DocId`. GHC 7.6.3 did not care at all about this when producing an instance `VecMut.MVector MVector DocId` with generalized newtype deriving, which is totally bogus because the derived instance has methods like `basicLength` of type `MVector s DocId -> Int`, even though there is no type `MVector s DocId` at all! A client can then define a mismatched instance `data instance MVector s DocId = Foo Char`, which will effectively be unsafely coerced to `MVector s Word32`, leading to undefined behavior (most likely a segfault). GHC 7.8 actually pays attention to what is going on here. To satisfy it all you need to do is define an instance for the data family in a way such that `MVector s DocId` is actually coercible to `MVector s Word32`. For example, `newtype instance MVector s DocId = DocVector (MVector s Word32)` will do the job. (Then you will want an instance for `VecBase.Vector`, too.) However, you will then immediately run into the other error involving the role of the parameter to `m` in the types of the other methods of `VecMut.MVector`, as discussed above. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9112#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler