aboutsummaryrefslogtreecommitdiff
path: root/src/Haddock/Convert.hs
diff options
context:
space:
mode:
authorMax Bolingbroke <batterseapower@hotmail.com>2011-09-09 13:34:29 +0100
committerMax Bolingbroke <batterseapower@hotmail.com>2011-09-09 14:10:25 +0100
commit2fed1c8a1dd4ce5713dde980b3a6f717ea6d6d5e (patch)
tree6fbaaa22d77308e149dbaf66d7f3d9bc95c2ed2e /src/Haddock/Convert.hs
parent0f21c474382af69bb7dac214d6c225218240e033 (diff)
parent7082a7c2278a963cc55cc5776618fbfe61f1fc77 (diff)
Merge branch 'no-pred-ty'
Conflicts: src/Haddock/Convert.hs
Diffstat (limited to 'src/Haddock/Convert.hs')
-rw-r--r--src/Haddock/Convert.hs86
1 files changed, 37 insertions, 49 deletions
diff --git a/src/Haddock/Convert.hs b/src/Haddock/Convert.hs
index 81435a6e..d4f75662 100644
--- a/src/Haddock/Convert.hs
+++ b/src/Haddock/Convert.hs
@@ -20,14 +20,16 @@ module Haddock.Convert where
import HsSyn
import TcType ( tcSplitTyConApp_maybe, tcSplitSigmaTy )
import TypeRep
+import Kind ( liftedTypeKind, constraintKind )
import Coercion ( splitKindFunTys, synTyConResKind )
import Name
import Var
import Class
import TyCon
import DataCon
+import BasicTypes ( TupleSort(..) )
import TysPrim ( alphaTyVars )
-import TysWiredIn ( listTyConName )
+import TysWiredIn ( listTyConName, eqTyCon )
import Bag ( emptyBag )
import SrcLoc ( Located, noLoc, unLoc )
@@ -47,7 +49,24 @@ tyThingToLHsDecl t = noLoc $ case t of
-- type-constructors (e.g. Maybe) are complicated, put the definition
-- later in the file (also it's used for class associated-types too.)
- ATyCon tc -> TyClD (synifyTyCon tc)
+ ATyCon tc
+ | Just cl <- tyConClass_maybe tc -- classes are just a little tedious
+ -> TyClD $ ClassDecl
+ (synifyCtx (classSCTheta cl))
+ (synifyName cl)
+ (synifyTyVars (classTyVars cl))
+ (map (\ (l,r) -> noLoc
+ (map getName l, map getName r) ) $
+ snd $ classTvsFds cl)
+ (map (noLoc . synifyIdSig DeleteTopLevelQuantification)
+ (classMethods cl))
+ emptyBag --ignore default method definitions, they don't affect signature
+ -- class associated-types are a subset of TyCon:
+ [noLoc (synifyTyCon at_tc) | (at_tc, _) <- classATItems cl]
+ [] --ignore associated type defaults
+ [] --we don't have any docs at this point
+ | otherwise
+ -> TyClD (synifyTyCon tc)
-- type-constructors (e.g. Maybe) are complicated, put the definition
-- later in the file (also it's used for class associated-types too.)
@@ -56,29 +75,6 @@ tyThingToLHsDecl t = noLoc $ case t of
-- a data-constructor alone just gets rendered as a function:
ADataCon dc -> SigD (TypeSig [synifyName dc]
(synifyType ImplicitizeForAll (dataConUserType dc)))
- -- classes are just a little tedious
- AClass cl ->
- TyClD $ ClassDecl
- (synifyCtx (classSCTheta cl))
- (synifyName cl)
- (synifyTyVars (classTyVars cl))
- (map (\ (l,r) -> noLoc
- (map getName l, map getName r) ) $
- snd $ classTvsFds cl)
- (map (noLoc . synifyIdSig DeleteTopLevelQuantification)
- (classMethods cl))
- emptyBag --ignore default method definitions, they don't affect signature
- ats
- (concat at_defss)
- [] --we don't have any docs at this point
- where (ats, at_defss) = unzip $ map synifyClassAT (classATItems cl)
-
-
--- class associated-types are a subset of TyCon
--- (mainly only type/data-families)
-synifyClassAT :: ClassATItem -> (LTyClDecl Name, [LTyClDecl Name])
-synifyClassAT (tc, _mb_defs) = (noLoc (synifyTyCon tc), [])
- -- ignore the mb_defs since we ignore default methods
synifyATDefault :: TyCon -> LTyClDecl Name
synifyATDefault tc = noLoc (synifyAxiom ax)
@@ -231,25 +227,7 @@ synifyIdSig s i = TypeSig [synifyName i] (synifyType s (varType i))
synifyCtx :: [PredType] -> LHsContext Name
-synifyCtx = noLoc . map synifyPred
-
-
-synifyPred :: PredType -> LHsPred Name
-synifyPred (ClassP cls tys) =
- let sTys = map (synifyType WithinType) tys
- in noLoc $
- HsClassP (getName cls) sTys
-synifyPred (IParam ip ty) =
- let sTy = synifyType WithinType ty
- -- IPName should be in class NamedThing...
- in noLoc $
- HsIParam ip sTy
-synifyPred (EqPred ty1 ty2) =
- let
- s1 = synifyType WithinType ty1
- s2 = synifyType WithinType ty2
- in noLoc $
- HsEqualP s1 s2
+synifyCtx = noLoc . map (synifyType WithinType)
synifyTyVars :: [TyVar] -> [LHsTyVarBndr Name]
@@ -280,16 +258,26 @@ data SynifyTypeState
synifyType :: SynifyTypeState -> Type -> LHsType Name
-synifyType _ (PredTy{}) = --should never happen.
- error "synifyType: PredTys are not, in themselves, source-level types."
synifyType _ (TyVarTy tv) = noLoc $ HsTyVar (getName tv)
synifyType _ (TyConApp tc tys)
-- Use non-prefix tuple syntax where possible, because it looks nicer.
| isTupleTyCon tc, tyConArity tc == length tys =
- noLoc $ HsTupleTy (tupleTyConBoxity tc) (map (synifyType WithinType) tys)
+ noLoc $ HsTupleTy (case tupleTyConSort tc of
+ BoxedTuple -> HsBoxyTuple liftedTypeKind
+ FactTuple -> HsBoxyTuple constraintKind
+ UnboxedTuple -> HsUnboxedTuple)
+ (map (synifyType WithinType) tys)
-- ditto for lists
| getName tc == listTyConName, [ty] <- tys =
noLoc $ HsListTy (synifyType WithinType ty)
+ -- ditto for implicit parameter tycons
+ | Just ip <- tyConIP_maybe tc
+ , [ty] <- tys
+ = noLoc $ HsIParamTy ip (synifyType WithinType ty)
+ -- and equalities
+ | tc == eqTyCon
+ , [ty1, ty2] <- tys
+ = noLoc $ HsEqTy (synifyType WithinType ty1) (synifyType WithinType ty2)
-- Most TyCons:
| otherwise =
foldl (\t1 t2 -> noLoc (HsAppTy t1 t2))
@@ -320,9 +308,9 @@ synifyType s forallty@(ForAllTy _tv _ty) =
synifyInstHead :: ([TyVar], [PredType], Class, [Type]) ->
- ([HsPred Name], Name, [HsType Name])
+ ([HsType Name], Name, [HsType Name])
synifyInstHead (_, preds, cls, ts) =
- ( map (unLoc . synifyPred) preds
+ ( map (unLoc . synifyType WithinType) preds
, getName cls
, map (unLoc . synifyType WithinType) ts
)