Allow type defaulting for multi-param type classes with ExtendedDefaultRules
authorvivid-synth <vivid.haskell@gmail.com>
Tue, 14 Feb 2017 14:51:54 +0000 (09:51 -0500)
committerBen Gamari <ben@smart-cactus.org>
Tue, 14 Feb 2017 15:53:01 +0000 (10:53 -0500)
commitc3bbd1afc85cd634d8d26e27bafb92cc7481667b
tree729e78fe6b02eecef0035d4220cdad44d3b401a0
parent2f1017b924740e66f093b0baba62ac0b1528abf8
Allow type defaulting for multi-param type classes with ExtendedDefaultRules

Expressions like the following will now typecheck:

```
    data A x = A deriving Show

    class ToA a x where
       toA :: a -> A x

    instance ToA Integer x where
       toA _ = A

    main = print (toA 5 :: A Bool)
```

The new defaulting rules are

Find all the unsolved constraints. Then:

* Find those that have exactly one free type variable, and partition
  that subset into groups that share a common type variable `a`.
* Now default `a` (to one of the types in the default list) if at least
  one of the classes `Ci` is an interactive class

Reviewers: goldfire, bgamari, austin, mpickering, simonpj

Reviewed By: bgamari, simonpj

Subscribers: mpickering, simonpj, goldfire, thomie

Differential Revision: https://phabricator.haskell.org/D2822
compiler/typecheck/TcSimplify.hs
docs/users_guide/8.2.1-notes.rst
docs/users_guide/ghci.rst
testsuite/tests/typecheck/should_compile/T12923.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_compile/T12924.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_compile/T12926.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_compile/all.T