aboutsummaryrefslogtreecommitdiff
path: root/src/Haddock/Convert.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Haddock/Convert.hs')
-rw-r--r--src/Haddock/Convert.hs75
1 files changed, 35 insertions, 40 deletions
diff --git a/src/Haddock/Convert.hs b/src/Haddock/Convert.hs
index 34de6775..b3549fdc 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,22 @@ 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
+ (map synifyClassAT (classATs cl))
+ [] --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,20 +73,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
- (map synifyClassAT (classATs cl))
- [] --we don't have any docs at this point
-- class associated-types are a subset of TyCon
@@ -224,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]
@@ -273,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))
@@ -313,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
)