[GHC] #14662: Partial type signatures + mutual recursion = confusion

GHC ghc-devs at haskell.org
Thu Jan 11 22:33:54 UTC 2018


#14662: Partial type signatures + mutual recursion = confusion
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.2
      Resolution:                    |             Keywords:
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):

 > If the user quantifies a partial type signature (either by using forall,
 or just using an out-of-scope type variable and using Haskell's implicit
 quantification), why can't we use polymorphic recursion with that
 variable?

 I recommend caution.  Partial type signatures were implemented fairly
 quickly by a PhD student some time ago, but I have spent many hours since
 slowly fixing bugs in the implementation.  It's much trickier than I
 supposed at first.  (So I'm not blaming him!  And its a very nice
 feature.)

 Here's a core principle: partial type signatures go entirely via the
 `InferGen` plan: that is, we use only monomorphic rcursion exactly as if
 there was no signature.  All the signature does is to impose a partial
 shape on the type of the RHS, including restricting some parts of that
 type to type variables -- hence the `SigTvs`.  (I don't share your
 dislike; `SigTvs` are very nice actually.)

 Yes, you could imagine some kind of partial polymorphic recursion, but I
 don't think it makes sense.  Eg
 {{{
 f :: forall a. _ -> a
 f =  ...f @Int...f @Bool.....
 }}}
 That wildcard might end up being `a`! If it did, then would the recursive
 occurrences get instantiate to `Int->Int` and `Bool->Bool`.  Certainly
 not.

 This way lies madness.  The current implementation is quite complicated
 enough.

 I agree that documentation is lacking: no, polymorphic recursion is
 absolutely not available for functions with a partial type signature.

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


More information about the ghc-tickets mailing list