Skip to content
Snippets Groups Projects
Forked from Glasgow Haskell Compiler / GHC
13912 commits behind the upstream repository.
  • Ryan Scott's avatar
    8ed8b037
    Introduce DerivingVia · 8ed8b037
    Ryan Scott authored
    This implements the `DerivingVia` proposal put forth in
    https://github.com/ghc-proposals/ghc-proposals/pull/120.
    
    This introduces the `DerivingVia` deriving strategy. This is a
    generalization of `GeneralizedNewtypeDeriving` that permits the user
    to specify the type to `coerce` from.
    
    The major change in this patch is the introduction of the
    `ViaStrategy` constructor to `DerivStrategy`, which takes a type
    as a field. As a result, `DerivStrategy` is no longer a simple
    enumeration type, but rather something that must be renamed and
    typechecked. The process by which this is done is explained more
    thoroughly in section 3 of this paper
    ( https://www.kosmikus.org/DerivingVia/deriving-via-paper.pdf ),
    although I have inlined the relevant parts into Notes where possible.
    
    There are some knock-on changes as well. I took the opportunity to
    do some refactoring of code in `TcDeriv`, especially the
    `mkNewTypeEqn` function, since it was bundling all of the logic for
    (1) deriving instances for newtypes and
    (2) `GeneralizedNewtypeDeriving`
    into one huge broth. `DerivingVia` reuses much of part (2), so that
    was factored out as much as possible.
    
    Bumps the Haddock submodule.
    
    Test Plan: ./validate
    
    Reviewers: simonpj, bgamari, goldfire, alanz
    
    Subscribers: alanz, goldfire, rwbarton, thomie, mpickering, carter
    
    GHC Trac Issues: #15178
    
    Differential Revision: https://phabricator.haskell.org/D4684
    8ed8b037
    History
    Introduce DerivingVia
    Ryan Scott authored
    This implements the `DerivingVia` proposal put forth in
    https://github.com/ghc-proposals/ghc-proposals/pull/120.
    
    This introduces the `DerivingVia` deriving strategy. This is a
    generalization of `GeneralizedNewtypeDeriving` that permits the user
    to specify the type to `coerce` from.
    
    The major change in this patch is the introduction of the
    `ViaStrategy` constructor to `DerivStrategy`, which takes a type
    as a field. As a result, `DerivStrategy` is no longer a simple
    enumeration type, but rather something that must be renamed and
    typechecked. The process by which this is done is explained more
    thoroughly in section 3 of this paper
    ( https://www.kosmikus.org/DerivingVia/deriving-via-paper.pdf ),
    although I have inlined the relevant parts into Notes where possible.
    
    There are some knock-on changes as well. I took the opportunity to
    do some refactoring of code in `TcDeriv`, especially the
    `mkNewTypeEqn` function, since it was bundling all of the logic for
    (1) deriving instances for newtypes and
    (2) `GeneralizedNewtypeDeriving`
    into one huge broth. `DerivingVia` reuses much of part (2), so that
    was factored out as much as possible.
    
    Bumps the Haddock submodule.
    
    Test Plan: ./validate
    
    Reviewers: simonpj, bgamari, goldfire, alanz
    
    Subscribers: alanz, goldfire, rwbarton, thomie, mpickering, carter
    
    GHC Trac Issues: #15178
    
    Differential Revision: https://phabricator.haskell.org/D4684
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
deriving-via-fail4.stderr 876 B

deriving-via-fail4.hs:14:12: error:
    • Couldn't match representation of type ‘Int’ with that of ‘Char’
        arising from the coercion of the method ‘==’
          from type ‘Char -> Char -> Bool’ to type ‘F1 -> F1 -> Bool’
    • When deriving the instance for (Eq F1)

deriving-via-fail4.hs:17:13: error:
    • Couldn't match representation of type ‘a1’ with that of ‘a’
        arising from the coercion of the method ‘c’
          from type ‘a -> a -> Bool’ to type ‘a -> F2 a1 -> Bool’
      ‘a1’ is a rigid type variable bound by
        the deriving clause for ‘C a (F2 a1)’
        at deriving-via-fail4.hs:17:13-15
      ‘a’ is a rigid type variable bound by
        the deriving clause for ‘C a (F2 a1)’
        at deriving-via-fail4.hs:17:13-15
    • When deriving the instance for (C a (F2 a1))