From 2d9c6a02b4bc2c2561d627eac4029ad8aa03c751 Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Wed, 31 Dec 2008 15:25:17 +0000 Subject: [PATCH] -XImpredicativeTypes implies -XRankNTypes, and improve error msg in TcMType If you are going for impredicative types you almost certainly want RankN too. The change to TcMType improves the error when you say T (forall a. blah) where T is a type synonym. This doesn't necessarily need impredicativity, if you have LiberalTypeSynonyms. --- compiler/main/DynFlags.hs | 1 + compiler/typecheck/TcMType.lhs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index d04dade..f67bb4e 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -1792,6 +1792,7 @@ impliedFlags , (Opt_ScopedTypeVariables, Opt_RelaxedPolyRec) -- Ditto for scoped type variables; see -- Note [Scoped tyvars] in TcBinds + , (Opt_ImpredicativeTypes, Opt_RankNTypes) ] glasgowExtsFlags :: [DynFlag] diff --git a/compiler/typecheck/TcMType.lhs b/compiler/typecheck/TcMType.lhs index 6de3dd2..75ce6c9 100644 --- a/compiler/typecheck/TcMType.lhs +++ b/compiler/typecheck/TcMType.lhs @@ -1066,6 +1066,7 @@ checkValidMonoType ty = check_mono_type MustBeMonoType ty data Rank = ArbitraryRank -- Any rank ok | MustBeMonoType -- Monotype regardless of flags | TyConArgMonoType -- Monotype but could be poly if -XImpredicativeTypes + | SynArgMonoType -- Monotype but could be poly if -XLiberalTypeSynonyms | Rank Int -- Rank n, but could be more with -XRankNTypes decRank :: Rank -> Rank -- Function arguments @@ -1139,7 +1140,7 @@ check_type rank ubx_tup ty@(TyConApp tc tys) ; liberal <- doptM Opt_LiberalTypeSynonyms ; if not liberal || isOpenSynTyCon tc then -- For H98 and synonym families, do check the type args - mapM_ (check_mono_type TyConArgMonoType) tys + mapM_ (check_mono_type SynArgMonoType) tys else -- In the liberal case (only for closed syns), expand then check case tcView ty of @@ -1216,6 +1217,7 @@ forAllTyErr rank ty suggestion = case rank of Rank _ -> ptext (sLit "Perhaps you intended to use -XRankNTypes or -XRank2Types") TyConArgMonoType -> ptext (sLit "Perhaps you intended to use -XImpredicativeTypes") + SynArgMonoType -> ptext (sLit "Perhaps you intended to use -XLiberalTypeSynonyms") _ -> empty -- Polytype is always illegal unliftedArgErr, ubxArgTyErr :: Type -> SDoc -- 1.7.10.4