Skip to content
  • Ryan Scott's avatar
    Track the order of user-written tyvars in DataCon · ef26182e
    Ryan Scott authored
    After typechecking a data constructor's type signature, its type
    variables are partitioned into two distinct groups: the universally
    quantified type variables and the existentially quantified type
    variables. Then, when prompted for the type of the data constructor,
    GHC gives this:
    
    ```lang=haskell
    MkT :: forall <univs> <exis>. (...)
    ```
    
    For H98-style datatypes, this is a fine thing to do. But for GADTs,
    this can sometimes produce undesired results with respect to
    `TypeApplications`. For instance, consider this datatype:
    
    ```lang=haskell
    data T a where
      MkT :: forall b a. b -> T a
    ```
    
    Here, the user clearly intended to have `b` be available for visible
    type application before `a`. That is, the user would expect
    `MkT @Int @Char` to be of type `Int -> T Char`, //not//
    `Char -> T Int`. But alas, up until now that was not how GHC
    operated—regardless of the order in which the user actually wrote
    the tyvars, GHC would give `MkT` the type:
    
    ```lang=haskell
    Mk...
    ef26182e