diff options
author | Andrei Borzenkov <andreyborzenkov2002@gmail.com> | 2023-04-22 16:19:01 +0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2023-04-25 18:13:19 -0400 |
commit | 74c557121fbcae32abd3b4a69513f8aa7d536073 (patch) | |
tree | c0cc630bd86317124722e9302b0bc694fc02afe8 /docs/users_guide | |
parent | 8f656188e271fc55b31a50a1c2f3cf6ff9bbeeea (diff) | |
download | haskell-74c557121fbcae32abd3b4a69513f8aa7d536073.tar.gz |
Give more guarntees about ImplicitParams (#23289)
- Added new section in the GHC user's guide that legends behavior of
nested implicit parameter bindings in these two cases:
let ?f = 1 in let ?f = 2 in ?f
and
data T where MkT :: (?f :: Int) => T
f :: T -> T -> Int
f MkT MkT = ?f
- Added new test case to examine this behavior.
Diffstat (limited to 'docs/users_guide')
-rw-r--r-- | docs/users_guide/exts/implicit_parameters.rst | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/docs/users_guide/exts/implicit_parameters.rst b/docs/users_guide/exts/implicit_parameters.rst index a8da87e416..ee6234e55a 100644 --- a/docs/users_guide/exts/implicit_parameters.rst +++ b/docs/users_guide/exts/implicit_parameters.rst @@ -180,6 +180,27 @@ parameter. So we get the following results in GHCi: Adding a type signature dramatically changes the result! This is a rather counter-intuitive phenomenon, worth watching out for. +Implicit parameters scoping guarantees +------------------------------------- + +GHC always takes the most nested implicit parameter binding from the +context to find the value. Consider the following code:: + + let ?f = 1 in let ?f = 2 in ?f + +This expression will always return 2. + +Another example of this rule is matching over constructors with constraints. +For example:: + + data T where + MkT :: (?f :: Int) => T + + f :: T -> T -> Int + f MkT MkT = ?f + +Here GHC will always take ``?f`` from the last match. + Implicit parameters and monomorphism ------------------------------------ @@ -199,5 +220,3 @@ a type signature for ``y``, then ``y`` will get type ``(?x::Int) => Int``, so the occurrence of ``y`` in the body of the ``let`` will see the inner binding of ``?x``, so ``(f 9)`` will return ``14``. - - |