[GHC] #15379: Don't reject user-written instances of KnownNat and friends in hsig files

GHC ghc-devs at haskell.org
Wed Jul 18 10:30:57 UTC 2018


#15379: Don't reject user-written instances of KnownNat and friends in hsig files
-------------------------------------+-------------------------------------
        Reporter:  ezyang            |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:  backpack
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 The current implementation only ever has instances for `KnownNat 1`,
 `KnownNat 2` etc.  This is described in `Note [KnownNat & KnownSymbol and
 EvLit]` in `TcInteract`.

 But now you want to allow `instance KnownNat T` for some abstract type
 `T`; you explain this well in comment:4.

 Very well; but I really dislike messing with `matchInstEnv`.  Better: make
 `mathKnownNat` have an `otherwise` case that, instead of returning
 `NoInstance` uses `matchInstEnv`.  With  a careful `Note` to explain.

 Interestingly, `matchHasField` already does this, but without explanation
 :-(.

 I also worry about the other classes treated specially in
 `matchGlobalInst`.  For some (`matchCTuple` , `matchLiftedEquality`,
 `matchLiftedCoercible`) they can't fail, so that's fine.  But `Typeable`
 can fail; I wonder if you might end up wanting a `Typeable` instance in a
 `hsig` file.  I think that's all... but the big point is that GHC's
 treatment of built-in classes may need attention because of Backpack;
 KnownNat is just an example.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15379#comment:7>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list