diff options
author | Iavor S. Diatchki <iavor.diatchki@gmail.com> | 2012-05-26 15:21:12 -0700 |
---|---|---|
committer | Iavor S. Diatchki <iavor.diatchki@gmail.com> | 2012-05-26 15:21:12 -0700 |
commit | 9c98fa69c0ed0693bc40a440d19a24d8f3a76ab6 (patch) | |
tree | a24e8014fb535b9326342e977b8257c95b2eb278 | |
parent | b3480104266370fb370b673764f8236428f167fe (diff) | |
download | haskell-9c98fa69c0ed0693bc40a440d19a24d8f3a76ab6.tar.gz |
Desugar `?x :: t` into `IP "x" t`.
Note that the `IP` constraint requires a "flexible" context/instance,
which is why when -XImplictParams is on, it also turns on
-XFlexibleInstances and -XFlexibleContexts
-rw-r--r-- | compiler/main/DynFlags.hs | 5 | ||||
-rw-r--r-- | compiler/typecheck/TcHsType.lhs | 6 |
2 files changed, 10 insertions, 1 deletions
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index 31eb368b3f..2d6abea4ec 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -2127,6 +2127,11 @@ impliedFlags , (Opt_RecordWildCards, turnOn, Opt_DisambiguateRecordFields) , (Opt_ParallelArrays, turnOn, Opt_ParallelListComp) + + -- An implicit parameter constraint, `?x::Int`, is desugared into + -- `IP "x" Int`, which requires a flexible context/instance. + , (Opt_ImplicitParams, turnOn, Opt_FlexibleContexts) + , (Opt_ImplicitParams, turnOn, Opt_FlexibleInstances) ] optLevelFlags :: [([Int], DynFlag)] diff --git a/compiler/typecheck/TcHsType.lhs b/compiler/typecheck/TcHsType.lhs index b780c3b2e0..b5adc925c5 100644 --- a/compiler/typecheck/TcHsType.lhs +++ b/compiler/typecheck/TcHsType.lhs @@ -74,6 +74,7 @@ import UniqSupply import Outputable import FastString import Control.Monad ( unless, when, zipWithM ) +import PrelNames(ipClassName) \end{code} @@ -420,7 +421,10 @@ tc_hs_type ipTy@(HsIParamTy n ty) exp_kind = do { ty' <- tc_lhs_type ty (EK liftedTypeKind (ptext (sLit "The type argument of the implicit parameter had"))) ; checkExpectedKind ipTy constraintKind exp_kind - ; return (mkIPPred n ty') } + ; ipClass <- tcLookupClass ipClassName + ; let n' = mkStrLitTy $ occNameFS $ nameOccName $ ipNameName n + ; return (mkClassPred ipClass [n',ty']) + } tc_hs_type ty@(HsEqTy ty1 ty2) exp_kind = do { (ty1', kind1) <- tc_infer_lhs_type ty1 |