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

GHC ghc-devs at haskell.org
Tue Jul 17 06:48:24 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 ppk):

 Resolving the overlapping instance problem is more tricky than I thought.
 I am adding additional notes
 here so that some one can better guide the process. This is my current
 understanding on the issues

 The `KnownNat` and `KnownSymbol` instance witness and dictionary
 generating is done by ghc itself in
 the file `compiler/typecheck/ClsInst.hs`. However this is problematic in
 the backpack setting because of
 the following

 Let us consider the following signature fragment

 {{{#!haskell

 signature Abstract where
   data Foo :: Nat
   instance KnownNat Foo

 }}}

 Suppose this abstract signature is included in a module `Util`

 {{{#!haskell

 module Util where
   import Abstract
   printFoo :: IO ()
   printFoo = do print $ natVal (Proxy :: Proxy Foo)

 }}}

 Notice that the `natVal` function will need a dictionary of `KnownNat Foo`
 at this point and will need to get it from a concrete implementation of
 the kind

 {{{#!haskell

 module Concrete where
    type Foo = 42

 }}}

 It is not clear to me how this can be generated "inside the compiler" like
 what happens in `ClsInst.hs`.

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


More information about the ghc-tickets mailing list