- -- Collect all variables (1st arg serves as an accumulator)
- collect tvs (L l (HsForAllTy _ _ _ _)) =
- parseError l "Forall type not allowed as type parameter"
- collect tvs (L l (HsTyVar tv))
- | isRdrTyVar tv = return $ L l (UserTyVar tv) : tvs
- | otherwise = return tvs
- collect tvs (L l (HsBangTy _ _ )) =
- parseError l "Bang-style type annotations not allowed as type parameter"
- collect tvs (L l (HsAppTy t1 t2 )) = do
- tvs' <- collect tvs t2
- collect tvs' t1
- collect tvs (L l (HsFunTy t1 t2 )) = do
- tvs' <- collect tvs t2
- collect tvs' t1
- collect tvs (L l (HsListTy t )) = collect tvs t
- collect tvs (L l (HsPArrTy t )) = collect tvs t
- collect tvs (L l (HsTupleTy _ ts )) = collects tvs ts
- collect tvs (L l (HsOpTy t1 _ t2 )) = do
- tvs' <- collect tvs t2
- collect tvs' t1
- collect tvs (L l (HsParTy t )) = collect tvs t
- collect tvs (L l (HsNumTy t )) = return tvs
- collect tvs (L l (HsPredTy t )) =
- parseError l "Predicate not allowed as type parameter"
- collect tvs (L l (HsKindSig (L _ (HsTyVar tv)) k))
- | isRdrTyVar tv =
- return $ L l (KindedTyVar tv k) : tvs
- | otherwise =
- parseError l "Kind signature only allowed for type variables"
- collect tvs (L l (HsSpliceTy t )) =
- parseError l "Splice not allowed as type parameter"
+ -- Collect all variables (2nd arg serves as an accumulator)
+ collect :: LHsType RdrName -> [LHsTyVarBndr RdrName]
+ -> P [LHsTyVarBndr RdrName]
+ collect (L l (HsForAllTy _ _ _ _)) =
+ const $ parseError l "Forall type not allowed as type parameter"
+ collect (L l (HsTyVar tv))
+ | isRdrTyVar tv = return . (L l (UserTyVar tv) :)
+ | otherwise = return
+ collect (L l (HsBangTy _ _ )) =
+ const $ parseError l "Bang-style type annotations not allowed as type parameter"
+ collect (L _ (HsAppTy t1 t2 )) = collect t2 >=> collect t1
+ collect (L _ (HsFunTy t1 t2 )) = collect t2 >=> collect t1
+ collect (L _ (HsListTy t )) = collect t
+ collect (L _ (HsPArrTy t )) = collect t
+ collect (L _ (HsTupleTy _ ts )) = collects ts
+ collect (L _ (HsOpTy t1 _ t2 )) = collect t2 >=> collect t1
+ collect (L _ (HsParTy t )) = collect t
+ collect (L _ (HsNumTy _ )) = return
+ collect (L l (HsPredTy _ )) =
+ const $ parseError l "Predicate not allowed as type parameter"
+ collect (L l (HsKindSig (L _ (HsTyVar tv)) k))
+ | isRdrTyVar tv =
+ return . (L l (KindedTyVar tv k) :)
+ | otherwise =
+ const $ parseError l "Kind signature only allowed for type variables"
+ collect (L l (HsSpliceTy _ )) =
+ const $ parseError l "Splice not allowed as type parameter"