diff options
Diffstat (limited to 'haddock-api/src/Haddock/Convert.hs')
| -rw-r--r-- | haddock-api/src/Haddock/Convert.hs | 67 | 
1 files changed, 37 insertions, 30 deletions
diff --git a/haddock-api/src/Haddock/Convert.hs b/haddock-api/src/Haddock/Convert.hs index ff34d271..49c471a4 100644 --- a/haddock-api/src/Haddock/Convert.hs +++ b/haddock-api/src/Haddock/Convert.hs @@ -96,17 +96,10 @@ tyThingToLHsDecl t = case t of    -- a data-constructor alone just gets rendered as a function:    AConLike (RealDataCon dc) -> allOK $ SigD (TypeSig [synifyName dc] -    (synifyType ImplicitizeForAll (dataConUserType dc)) []) +    (synifySigWcType ImplicitizeForAll (dataConUserType dc)))    AConLike (PatSynCon ps) -> -      let (univ_tvs, req_theta, ex_tvs, prov_theta, arg_tys, res_ty) = patSynSig ps -          qtvs = univ_tvs ++ ex_tvs -          ty = mkFunTys arg_tys res_ty -      in allOK . SigD $ PatSynSig (synifyName ps) -                          (Implicit, synifyTyVars qtvs) -                          (synifyCtx req_theta) -                          (synifyCtx prov_theta) -                          (synifyType WithinType ty) +     allOK . SigD $ PatSynSig (synifyName ps) (synifySigType WithinType (patSynType ps))    where      withErrs e x = return (e, x)      allOK x = return (mempty, x) @@ -118,10 +111,9 @@ synifyAxBranch tc (CoAxBranch { cab_tvs = tkvs, cab_lhs = args, cab_rhs = rhs })          hs_rhs     = synifyType WithinType rhs          (kvs, tvs) = partition isKindVar tkvs      in TyFamEqn { tfe_tycon = name -                , tfe_pats  = HsWB { hswb_cts = typats -                                    , hswb_kvs = map tyVarName kvs -                                    , hswb_tvs = map tyVarName tvs -                                    , hswb_wcs = [] } +                , tfe_pats  = HsIB { hsib_body = typats +                                   , hsib_kvs = map tyVarName kvs +                                   , hsib_tvs = map tyVarName tvs }                  , tfe_rhs   = hs_rhs }  synifyAxiom :: CoAxiom br -> Either ErrMsg (HsDecl Name) @@ -305,32 +297,40 @@ synifyDataCon use_gadt_syntax dc =                else ResTyH98   -- finally we get synifyDataCon's result!   in hs_arg_tys >>= -      \hat -> return . noLoc $ ConDecl [name] Implicit -- we don't know nor care -                qvars ctx hat hs_res_ty Nothing +      \hat -> return $ noLoc $ +              ConDecl { con_names = [name] +                      , con_explicit = False    -- we don't know nor care +                      , con_qvars = qvars +                      , con_cxt   = ctx +                      , con_details =  hat +                      , con_res = hs_res_ty +                      , con_doc =  Nothing }  synifyName :: NamedThing n => n -> Located Name  synifyName = noLoc . getName  synifyIdSig :: SynifyTypeState -> Id -> Sig Name -synifyIdSig s i = TypeSig [synifyName i] (synifyType s (varType i)) [] +synifyIdSig s i = TypeSig [synifyName i] (synifySigWcType s (varType i))  synifyCtx :: [PredType] -> LHsContext Name  synifyCtx = noLoc . map (synifyType WithinType) -synifyTyVars :: [TyVar] -> LHsTyVarBndrs Name +synifyTyVars :: [TyVar] -> LHsQTyVars Name  synifyTyVars ktvs = HsQTvs { hsq_kvs = map tyVarName kvs                             , hsq_tvs = map synifyTyVar tvs }    where      (kvs, tvs) = partition isKindVar ktvs -    synifyTyVar tv -      | isLiftedTypeKind kind = noLoc (UserTyVar (noLoc name)) -      | otherwise             = noLoc (KindedTyVar (noLoc name) (synifyKindSig kind)) -      where -        kind = tyVarKind tv -        name = getName tv + +synifyTyVar :: TyVar -> LHsTyVarBndr Name +synifyTyVar tv +  | isLiftedTypeKind kind = noLoc (UserTyVar (noLoc name)) +  | otherwise             = noLoc (KindedTyVar (noLoc name) (synifyKindSig kind)) +  where +    kind = tyVarKind tv +    name = getName tv  --states of what to do with foralls:  data SynifyTypeState @@ -348,6 +348,15 @@ data SynifyTypeState    --   the defining class gets to quantify all its functions for free! +synifySigType :: SynifyTypeState -> Type -> LHsSigType Name +-- The empty binders is a bit suspicious; +-- what if the type has free variables? +synifySigType s ty = mkEmptyImplicitBndrs (synifyType s ty) + +synifySigWcType :: SynifyTypeState -> Type -> LHsSigWcType Name +-- Ditto (see synifySigType) +synifySigWcType s ty = mkEmptyImplicitBndrs (mkEmptyWildCardBndrs (synifyType s ty)) +  synifyType :: SynifyTypeState -> Type -> LHsType Name  synifyType _ (TyVarTy tv) = noLoc $ HsTyVar $ noLoc (getName tv)  synifyType _ (TyConApp tc tys) @@ -386,15 +395,13 @@ synifyType _ (FunTy t1 t2) = let    in noLoc $ HsFunTy s1 s2  synifyType s forallty@(ForAllTy _tv _ty) =    let (tvs, ctx, tau) = tcSplitSigmaTy forallty -      sTvs = synifyTyVars tvs -      sCtx = synifyCtx ctx -      sTau = synifyType WithinType tau -      mkHsForAllTy forallPlicitness = -        noLoc $ HsForAllTy forallPlicitness Nothing sTvs sCtx sTau +      sPhi = HsQualTy { hst_ctxt = synifyCtx ctx +                      , hst_body = synifyType WithinType tau }    in case s of      DeleteTopLevelQuantification -> synifyType ImplicitizeForAll tau -    WithinType -> mkHsForAllTy Explicit -    ImplicitizeForAll -> mkHsForAllTy Implicit +    WithinType        -> noLoc $ HsForAllTy { hst_bndrs = map synifyTyVar tvs +                                            , hst_body  = noLoc sPhi } +    ImplicitizeForAll -> noLoc sPhi  synifyType _ (LitTy t) = noLoc $ HsTyLit $ synifyTyLit t  | 
