diff options
| author | Rodrigo Mesquita <rodrigo.m.mesquita@gmail.com> | 2023-05-11 13:39:00 +0100 |
|---|---|---|
| committer | Rodrigo Mesquita <rodrigo.m.mesquita@gmail.com> | 2023-05-11 13:39:00 +0100 |
| commit | 9e29c1644350f13a1804a53cc57269064ffe5c56 (patch) | |
| tree | 5f5574322dd0901de13e2e5892d5076f21bd95bd | |
| parent | ad9e35708d29f9a90257a66ab2b5a9e908342f2a (diff) | |
| download | haskell-9e29c1644350f13a1804a53cc57269064ffe5c56.tar.gz | |
Document 'selectMatchVars'
| -rw-r--r-- | compiler/GHC/HsToCore/Utils.hs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/compiler/GHC/HsToCore/Utils.hs b/compiler/GHC/HsToCore/Utils.hs index f6aad3bb71..0aad7eab1a 100644 --- a/compiler/GHC/HsToCore/Utils.hs +++ b/compiler/GHC/HsToCore/Utils.hs @@ -110,7 +110,7 @@ selectSimpleMatchVarL :: Mult -> LPat GhcTc -> DsM Id -- Postcondition: the returned Id has an Internal Name selectSimpleMatchVarL w pat = selectMatchVar w (unLoc pat) --- (selectMatchVars ps tys) chooses variables of type tys +-- | (selectMatchVars ps tys) chooses variables of type tys -- to use for matching ps against. If the pattern is a variable, -- we try to use that, to save inventing lots of fresh variables. -- @@ -125,11 +125,19 @@ selectSimpleMatchVarL w pat = selectMatchVar w (unLoc pat) -- f (T2 i) (y::a) = 0 -- Then we must not choose (x::Int) as the matching variable! -- And nowadays we won't, because the (x::Int) will be wrapped in a CoPat - selectMatchVars :: HasCallStack => [(Mult, Pat GhcTc)] -> DsM [Id] -- Postcondition: the returned Ids have Internal Names selectMatchVars ps = mapM (uncurry selectMatchVar) ps +-- | 'selectMatchVar' chooses a variable to use for matching against the pattern. +-- +-- In particular, for as-patterns and variable patterns we can re-use the +-- existing variable, while for other patterns we must invent a fresh variable. +-- +-- For the following example patterns, +-- (1) let !(x@(C a b)) = ... -- `x` is chosen +-- (2) let ~y = ... -- `y` is chosen +-- (3) let (a,b) = ... -- fresh `z` is chosen selectMatchVar :: HasCallStack => Mult -> Pat GhcTc -> DsM Id -- Postcondition: the returned Id has an Internal Name selectMatchVar w (BangPat _ pat) = selectMatchVar w (unLoc pat) |
