[GHC] #15885: Enhancing COMPLETE pragma to support pattern synonyms with polymorphic (output) types

GHC ghc-devs at haskell.org
Sat Nov 10 01:17:11 UTC 2018


#15885: Enhancing COMPLETE pragma to support pattern synonyms with polymorphic
(output) types
-------------------------------------+-------------------------------------
           Reporter:  Shayan-Najd    |             Owner:  (none)
               Type:  task           |            Status:  new
           Priority:  normal         |         Milestone:  8.6.3
          Component:  Compiler       |           Version:  8.6.2
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 On our work on the
 [https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow new
 front-end AST for GHC] based on
 [https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow/TreesThatGrowGuidance
 TTG], we would like to use
 [https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow/HandlingSourceLocations
 a pattern synonym] similar to the following:

 {{{#!hs
 pattern LL :: HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
 pattern LL s m <- (decomposeSrcSpan -> (m , s))
   where
         LL s m =  composeSrcSpan (m , s)
 }}}

 We know that any match on `LL` patterns, makes the pattern matching total,
 as it uses a view pattern with a total output pattern (i.e., in
 `decomposeSrcSpan -> (m , s)`, the pattern `(m , s)` is total).

 As far as I understand, currently COMPLETE pragmas cannot be used with
 such a polymorphic pattern synonym.
 I believe we need to enhance COMPLETE pragmas to support such pattern
 synonyms.

 This can be done either syntactically, or (preferably) type-directed.

 For example, we should be able to write `{-# COMPLETE LL #-}` or `{-#
 COMPLETE LL :: HasSrcSpan a => a #-}`.

 In the type-directed approach
 a. the totality checker *may* need to track, at least, the set of required
 constraints of pattern synonyms mentioned in a COMPLETE pragma; and
 b. the order of pattern synonyms mentioned in a pragma should be taken
 into account (as noted by @carter).

 For example, in the case of `LL`, `HasSrcSpan a` is a required type
 constraint.

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


More information about the ghc-tickets mailing list