[GHC] #9813: Error when reifying type constructor

GHC ghc-devs at haskell.org
Mon Feb 15 17:57:38 UTC 2016


#9813: Error when reifying type constructor
-------------------------------------+-------------------------------------
        Reporter:  owst              |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Template Haskell  |              Version:  7.8.3
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D1899
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by owst):

 Thank you both for clarifying things.

 So, to be explicit, the proposal is (at a conceptual level) now:

 1. Split the module into declaration groups (DG) and process top-to-
 bottom,
 2. For each DG:
  a. partition the declarations within it to two sets: those that contain
 splices (directly or via reference), which we refer to as S, and those
 that do not, which we refer to as NS,
  b. Process NS first, then S. Splices within S can refer (either with
 `reify` or via evaluation) to all names declared in NS or previous DGs),
 but no names within S.

 This allows:
 {{{
 f = $(mapM reify ['C, ''C, 'i] >>= ...) -- all names are in NS
 g = h f
 h x = $(LitE . StringL . i . show <$> reify 'i) -- both call and reify i
 i x = x
 data C = C

 $(return [])

 -- In a later DG, all earlier names are available, as are those in NS
 j = $(mapM reify ['C, ''C, 'f, 'g, 'h, 'i, 'k] >>= ...)
 k = ()
 }}}

 Here, we have two declaration groups:
 1. NS = `{i, C}`, S = `{f, g, h}`
 2. NS = `{k}`, S = `{j}` (with `i, C, f, g, h` all available for
 `reify`/evaluation)

 but not:
 {{{
 f = ()
 g = $(reify 'f ...) -- ok
 h = ... g ...
 i = $(reify 'g ...) -- Error: f is in S in this declaration group
 j = $(reify 'h ...) -- Error: h is in S in this declaration group
 k = $(reify 'l ...) -- Error: l is declared in the next declaration group
 $(return [])
 l x = ...
 }}}

 Here we also have two declaration groups, and in particular, `h` is
 contained in ''S'' in the first declaration group.

 So vs today:
 1. We loosen the stage restriction (allowing e.g. `h` to call `i`)
 2. Allow "no-splice" expressions to be referred to from a splice within
 the same declaration group (allowing e.g. `f` to `reify` both `C` and
 `i`).

 Both whilst not breaking existing programs. This seems good!

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


More information about the ghc-tickets mailing list