summaryrefslogtreecommitdiff
path: root/ghc
diff options
context:
space:
mode:
authorXavier Denis <xldenis@gmail.com>2018-10-20 01:36:23 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-06-04 14:41:29 -0400
commit002594b731c40334b33eb883275e9c274c68e9ac (patch)
tree3a35bccefc9f336cf42a37006ec90f3cebd2897c /ghc
parent114b014f7ed346727241c78ef3e0bf965d94edfc (diff)
downloadhaskell-002594b731c40334b33eb883275e9c274c68e9ac.tar.gz
Add GHCi :instances command
This commit adds the `:instances` command to ghci following proosal number 41. This makes it possible to query which instances are available to a given type. The output of this command is all the possible instances with type variables and constraints instantiated.
Diffstat (limited to 'ghc')
-rw-r--r--ghc/GHCi/UI.hs16
1 files changed, 15 insertions, 1 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index 5dc3aa7d4d..6929ee8a32 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -223,7 +223,8 @@ ghciCommands = map mkCmd [
("unadd", keepGoingPaths unAddModule, completeFilename),
("undef", keepGoing undefineMacro, completeMacro),
("unset", keepGoing unsetOptions, completeSetOptions),
- ("where", keepGoing whereCmd, noCompletion)
+ ("where", keepGoing whereCmd, noCompletion),
+ ("instances", keepGoing' instancesCmd, completeExpression)
] ++ map mkCmdHidden [ -- hidden commands
("all-types", keepGoing' allTypesCmd),
("complete", keepGoing completeCmd),
@@ -1780,6 +1781,19 @@ handleGetDocsFailure no_docs = do
InteractiveName -> ProgramError msg
-----------------------------------------------------------------------------
+-- :instances
+
+instancesCmd :: String -> InputT GHCi ()
+instancesCmd "" =
+ throwGhcException (CmdLineError "syntax: ':instances <type-you-want-instances-for>'")
+instancesCmd s = do
+ handleSourceError GHC.printException $ do
+ ty <- GHC.parseInstanceHead s
+ res <- GHC.getInstancesForType ty
+
+ printForUser $ vcat $ map ppr res
+
+-----------------------------------------------------------------------------
-- :load, :add, :reload
-- | Sets '-fdefer-type-errors' if 'defer' is true, executes 'load' and unsets