Skip to content
  • Ryan Scott's avatar
    Allow associated types to pattern-match in non-class-bound variables · 67345ccf
    Ryan Scott authored
    Summary:
    After 8136a5cb (#11450), if you have
    a class with an associated type:
    
    ```
    class C a where
      type T a b
    ```
    
    And you try to create an instance of `C` like this:
    
    ```
    instance C Int where
      type T Int Char = Bool
    ```
    
    Then it is rejected, since you're trying to instantiate the variable ``b`` with
    something other than a type variable. But this restriction proves quite
    onerous in practice, as it prevents you from doing things like this:
    
    ```
    class C a where
      type T a (b :: Identity c) :: c
    
    instance C Int where
      type T Int ('Identity x) = x
    ```
    
    You have to resort to an auxiliary type family in order to define this now,
    which becomes extremely tiring. This lifts this restriction and fixes #13398,
    in which it was discovered that adding this restriction broke code in the wild.
    
    Test Plan: ./validate
    
    Reviewers: simonpj, bgamari, austin
    
    Reviewed By: simonpj
    
    Subscribers: rwbarton, thomie
    
    Differential Revision: https://phabricator.haskell.org/D3302
    67345ccf