diff options
author | ross <unknown> | 2003-04-25 10:50:06 +0000 |
---|---|---|
committer | ross <unknown> | 2003-04-25 10:50:06 +0000 |
commit | eb12972c9b217d46397791c63d19c418b1a3c83f (patch) | |
tree | 2a9cd6bbbbb68ac69bd3991f9486f09a6a8108dd /src/HaddockRename.hs | |
parent | 6be4db86fa1f4a913db1e4703148edc83dc325e5 (diff) |
[haddock @ 2003-04-25 10:50:05 by ross]
An 80% solution to generating derived instances. A complete solution
would duplicate the instance inference logic, but if a type variable
occurs as a constructor argument, then we can just propagate the derived
class to the variable. But we know nothing of the constraints on any
type variables that occur elsewhere. For example, the declarations
data Either a b = Left a | Right b deriving (Eq, Ord)
data Ptr a = Ptr Addr# deriving (Eq, Ord)
newtype IORef a = IORef (STRef RealWorld a) deriving Eq
yield the instances
(Eq a, Eq b) => Eq (Either a b)
(Ord a, Ord b) => Ord (Either a b)
Eq (Ptr a)
Ord (Ptr a)
(??? a) => Eq (IORef a)
The last example shows the limits of this local analysis.
Note that a type variable may be in both categories: then we know a
constraint, but there may be more, or a stronger constraint, e.g.
data Tree a = Node a [Tree a] deriving Eq
yields
(Eq a, ??? a) => Eq (Tree a)
Diffstat (limited to 'src/HaddockRename.hs')
-rw-r--r-- | src/HaddockRename.hs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/HaddockRename.hs b/src/HaddockRename.hs index 77983e02..b539e9ff 100644 --- a/src/HaddockRename.hs +++ b/src/HaddockRename.hs @@ -88,12 +88,16 @@ renameDecl decl ty <- renameType ty0 doc <- renameMaybeDoc doc0 return (HsTypeDecl loc t args ty doc) - HsDataDecl loc ctx t args cons0 drv doc0 -> do + HsDataDecl loc ctx0 t args cons0 drv0 doc0 -> do + ctx <- mapM renamePred ctx0 cons <- mapM renameConDecl cons0 + drv <- mapM (lookupRn id) drv0 doc <- renameMaybeDoc doc0 return (HsDataDecl loc ctx t args cons drv doc) - HsNewTypeDecl loc ctx t args con0 drv doc0 -> do + HsNewTypeDecl loc ctx0 t args con0 drv0 doc0 -> do + ctx <- mapM renamePred ctx0 con <- renameConDecl con0 + drv <- mapM (lookupRn id) drv0 doc <- renameMaybeDoc doc0 return (HsNewTypeDecl loc ctx t args con drv doc) HsClassDecl loc ctxt0 nm tvs fds decls0 doc0 -> do |