summaryrefslogtreecommitdiff
path: root/compiler/hsSyn
diff options
context:
space:
mode:
authorMax Bolingbroke <batterseapower@hotmail.com>2011-09-06 09:04:37 +0100
committerMax Bolingbroke <batterseapower@hotmail.com>2011-09-09 08:26:59 +0100
commitde8c8d68cabb5f24304fad2f03caa41fdf182b4f (patch)
tree88e191e91aebad8ce2a2ef2bb467be73e0c4d063 /compiler/hsSyn
parent967633d4175a1d5ce525fa3194f53c219b5e2f91 (diff)
downloadhaskell-de8c8d68cabb5f24304fad2f03caa41fdf182b4f.tar.gz
Implement associated type defaults
Basically, now you can write: class Cls a where type Typ a type Typ a = Just a And now if an instance does not specify an explicit associated type instance, one will be generated afresh based on that default. So for example this instance: instance Cls Int where Will be equivalent to this one: instance Cls Int where type Typ Int = Just Int
Diffstat (limited to 'compiler/hsSyn')
-rw-r--r--compiler/hsSyn/Convert.lhs2
-rw-r--r--compiler/hsSyn/HsDecls.lhs12
2 files changed, 9 insertions, 5 deletions
diff --git a/compiler/hsSyn/Convert.lhs b/compiler/hsSyn/Convert.lhs
index f84776546a..90cf99d582 100644
--- a/compiler/hsSyn/Convert.lhs
+++ b/compiler/hsSyn/Convert.lhs
@@ -183,7 +183,7 @@ cvtDec (ClassD ctxt cl tvs fds decs)
; returnL $
TyClD $ ClassDecl { tcdCtxt = cxt', tcdLName = tc', tcdTyVars = tvs'
, tcdFDs = fds', tcdSigs = sigs', tcdMeths = binds'
- , tcdATs = ats', tcdDocs = [] }
+ , tcdATs = ats', tcdATDefs = [], tcdDocs = [] }
-- no docs in TH ^^
}
diff --git a/compiler/hsSyn/HsDecls.lhs b/compiler/hsSyn/HsDecls.lhs
index 82f113c096..940e6a73c3 100644
--- a/compiler/hsSyn/HsDecls.lhs
+++ b/compiler/hsSyn/HsDecls.lhs
@@ -499,7 +499,9 @@ data TyClDecl name
tcdSigs :: [LSig name], -- ^ Methods' signatures
tcdMeths :: LHsBinds name, -- ^ Default methods
tcdATs :: [LTyClDecl name], -- ^ Associated types; ie
- -- only 'TyFamily'
+ -- only 'TyFamily'
+ tcdATDefs :: [LTyClDecl name], -- ^ Associated type defaults; ie
+ -- only 'TySynonym'
tcdDocs :: [LDocDecl] -- ^ Haddock docs
}
deriving (Data, Typeable)
@@ -646,14 +648,16 @@ instance OutputableBndr name
ppr_sigx (Just kind) = dcolon <+> pprKind kind
ppr (ClassDecl {tcdCtxt = context, tcdLName = lclas, tcdTyVars = tyvars,
- tcdFDs = fds,
- tcdSigs = sigs, tcdMeths = methods, tcdATs = ats})
- | null sigs && null ats -- No "where" part
+ tcdFDs = fds,
+ tcdSigs = sigs, tcdMeths = methods,
+ tcdATs = ats, tcdATDefs = at_defs})
+ | null sigs && isEmptyBag methods && null ats && null at_defs -- No "where" part
= top_matter
| otherwise -- Laid out
= vcat [ top_matter <+> ptext (sLit "where")
, nest 2 $ pprDeclList (map ppr ats ++
+ map ppr at_defs ++
pprLHsBindsForUser methods sigs) ]
where
top_matter = ptext (sLit "class")