[commit: ghc] master: Show valid substitutions for typed holes (26c95f4)

git at git.haskell.org git at git.haskell.org
Wed Mar 29 23:03:42 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/26c95f46e679fb73e1ec2bec2be0801c72fd1449/ghc

>---------------------------------------------------------------

commit 26c95f46e679fb73e1ec2bec2be0801c72fd1449
Author: Matthías Páll Gissurarson <mpg at mpg.is>
Date:   Wed Mar 29 17:30:28 2017 -0400

    Show valid substitutions for typed holes
    
    The idea is to implement a mechanism similar to PureScript, where they
    suggest which identifiers in scope would fit the given hole. In
    PureScript, they use subsumption (which is what we would like here as
    well). For subsumption, we would have to check each type in scope
    whether the hole is a subtype of the given type, but that would require
    `tcSubType` and constraint satisfiability checking. Currently,
    `TcSimplify` uses a lot of functions from `TcErrors`, so that would
    require more of a rewrite, I will hold on with that for now, and submit
    the more simpler type equality version.
    
    As an example, consider
    
    ```
    ps :: String -> IO ()
    ps = putStrLn
    
    ps2 :: a -> IO ()
    ps2 _ = putStrLn "hello, world"
    
    main :: IO ()
    main = _ "hello, world"
    ```
    
    The results would be something like
    
    ```
        • Found hole: _ :: [Char] -> IO ()
        • In the expression: _
          In a stmt of a 'do' block: _ "hello, world"
          In the expression:
            do _ "hello, world"
        • Relevant bindings include
            main :: IO () (bound at test.hs:13:1)
            ps :: String -> IO () (bound at test.hs:7:1)
            ps2 :: forall a. a  -> IO () (bound at test.hs:10:1)
          Valid substitutions include
            putStrLn :: String
                        -> IO () (imported from ‘Prelude’ at
    test.hs:1:1-14
                                  (and originally defined in
    ‘System.IO’))
            putStr :: String
                      -> IO () (imported from ‘Prelude’ at
    test.hs:1:1-14
                                (and originally defined in ‘System.IO’))
    ```
    
    We'd like here for ps2 to be suggested as well, but for that we require
    subsumption.
    
    Reviewers: austin, bgamari, dfeuer, mpickering
    
    Reviewed By: dfeuer, mpickering
    
    Subscribers: mpickering, Wizek, dfeuer, rwbarton, thomie
    
    Differential Revision: https://phabricator.haskell.org/D3361


>---------------------------------------------------------------

26c95f46e679fb73e1ec2bec2be0801c72fd1449
 compiler/main/DynFlags.hs                          |   7 +
 compiler/typecheck/TcErrors.hs                     | 170 +++++++++++++++++++--
 docs/users_guide/using-optimisation.rst            |  10 ++
 testsuite/tests/ghci/scripts/T8353.stderr          |   5 +
 .../tests/typecheck/should_compile/T13050.stderr   |   5 +
 .../tests/typecheck/should_compile/ValidSubs.hs    |   4 +
 testsuite/tests/typecheck/should_compile/all.T     |   2 +
 .../should_compile/valid_substitutions.hs          |  19 +++
 .../should_compile/valid_substitutions.stderr      |  37 +++++
 utils/mkUserGuidePart/Options/Optimizations.hs     |   7 +
 10 files changed, 256 insertions(+), 10 deletions(-)

Diff suppressed because of size. To see it, use:

    git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc 26c95f46e679fb73e1ec2bec2be0801c72fd1449


More information about the ghc-commits mailing list