diff options
author | Xavier Denis <xldenis@gmail.com> | 2018-10-20 01:36:23 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-06-04 14:41:29 -0400 |
commit | 002594b731c40334b33eb883275e9c274c68e9ac (patch) | |
tree | 3a35bccefc9f336cf42a37006ec90f3cebd2897c /docs | |
parent | 114b014f7ed346727241c78ef3e0bf965d94edfc (diff) | |
download | haskell-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 'docs')
-rw-r--r-- | docs/users_guide/8.10.1-notes.rst | 5 | ||||
-rw-r--r-- | docs/users_guide/ghci.rst | 32 |
2 files changed, 37 insertions, 0 deletions
diff --git a/docs/users_guide/8.10.1-notes.rst b/docs/users_guide/8.10.1-notes.rst index 40241746a8..af6e177b2b 100644 --- a/docs/users_guide/8.10.1-notes.rst +++ b/docs/users_guide/8.10.1-notes.rst @@ -107,6 +107,11 @@ Compiler only convenient workaround was to enable `-fobject-code` for all modules. +GHCi +~~~~ + +- Added a command `:instances` to show the class instances available for a type. + Runtime system ~~~~~~~~~~~~~~ diff --git a/docs/users_guide/ghci.rst b/docs/users_guide/ghci.rst index 4b01724d9c..5f4b26eeb6 100644 --- a/docs/users_guide/ghci.rst +++ b/docs/users_guide/ghci.rst @@ -2539,6 +2539,38 @@ commonly used commands. The ``:loc-at`` command requires :ghci-cmd:`:set +c` to be set. +.. ghci-cmd:: :instances ⟨type⟩ + + Displays all the class instances available to the argument ⟨type⟩. + The command will match ⟨type⟩ with the first parameter of every + instance and then check that all constraints are satisfiable. + + When combined with ``-XPartialTypeSignatures``, a user can insert + wildcards into a query and learn the constraints required of each + wildcard for ⟨type⟩ match with an instance. + + The output is a listing of all matching instances, simplified and + instantiated as much as possible. + + For example: + + .. code-block:: none + >:instances Maybe (Maybe Int) + instance Eq (Maybe (Maybe Int)) -- Defined in ‘GHC.Maybe’ + instance Ord (Maybe (Maybe Int)) -- Defined in ‘GHC.Maybe’ + instance Show (Maybe (Maybe Int)) -- Defined in ‘GHC.Show’ + instance Read (Maybe (Maybe Int)) -- Defined in ‘GHC.Read’ + + >:set -XPartialTypeSignatures -fno-warn-partial-type-signatures + + >:instances Maybe _ + instance Eq _ => Eq (Maybe _) -- Defined in ‘GHC.Maybe’ + instance Semigroup _ => Monoid (Maybe _) -- Defined in ‘GHC.Base’ + instance Ord _ => Ord (Maybe _) -- Defined in ‘GHC.Maybe’ + instance Semigroup _ => Semigroup (Maybe _) -- Defined in ‘GHC.Base’ + instance Show _ => Show (Maybe _) -- Defined in ‘GHC.Show’ + instance Read _ => Read (Maybe _) -- Defined in ‘GHC.Read’ + .. ghci-cmd:: :main; ⟨arg1⟩ ... ⟨argn⟩ When a program is compiled and executed, it can use the ``getArgs`` |