diff options
Diffstat (limited to 'compiler/hsSyn/HsBinds.hs')
-rw-r--r-- | compiler/hsSyn/HsBinds.hs | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/compiler/hsSyn/HsBinds.hs b/compiler/hsSyn/HsBinds.hs index d0c345a9e5..f08a6af700 100644 --- a/compiler/hsSyn/HsBinds.hs +++ b/compiler/hsSyn/HsBinds.hs @@ -129,12 +129,41 @@ type LHsBindsLR idL idR = Bag (LHsBindLR idL idR) -- | Located Haskell Binding with separate Left and Right identifier types type LHsBindLR idL idR = Located (HsBindLR idL idR) +{- Note [Varieties of binding pattern matches] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The distinction between FunBind and PatBind is a bit subtle. FunBind covers +patterns which resemble function bindings and simple variable bindings. + + f x = e + f !x = e + f = e + !x = e -- FunRhs has SrcStrict + x `f` y = e -- FunRhs has Infix + +The actual patterns and RHSs of a FunBind are encoding in fun_matches. +The m_ctxt field of Match will be FunRhs and carries two bits of information +about the match, + + * the mc_strictness field describes whether the match is decorated with a bang + (e.g. `!x = e`) + * the mc_fixity field describes the fixity of the function binder + +By contrast, PatBind represents data constructor patterns, as well as a few +other interesting cases. Namely, + + Just x = e + (x) = e + x :: Ty = e +-} + -- | Haskell Binding with separate Left and Right id's data HsBindLR idL idR - = -- | Function Binding + = -- | Function-like Binding -- -- FunBind is used for both functions @f x = e@ -- and variables @f = \x -> e@ + -- and strict variables @!x = x + 1@ -- -- Reason 1: Special case for type inference: see 'TcBinds.tcMonoBinds'. -- @@ -145,6 +174,10 @@ data HsBindLR idL idR -- parses as a pattern binding, just like -- @(f :: a -> a) = ... @ -- + -- Strict bindings have their strictness recorded in the 'SrcStrictness' of their + -- 'MatchContext'. See Note [Varieties of binding pattern matches] for + -- details about the relationship between FunBind and PatBind. + -- -- 'ApiAnnotation.AnnKeywordId's -- -- - 'ApiAnnotation.AnnFunId', attached to each element of fun_matches @@ -185,7 +218,10 @@ data HsBindLR idL idR -- | Pattern Binding -- -- The pattern is never a simple variable; - -- That case is done by FunBind + -- That case is done by FunBind. + -- See Note [Varieties of binding pattern matches] for details about the + -- relationship between FunBind and PatBind. + -- -- - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnBang', -- 'ApiAnnotation.AnnEqual','ApiAnnotation.AnnWhere', |