Skip to content
  • Tom Murphy's avatar
    Allow type defaulting for multi-param type classes with ExtendedDefaultRules · c3bbd1af
    Tom Murphy authored
    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
    c3bbd1af