Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#2339 closed merge (fixed)

Template Haskell reification with mkName doesn't work right

Reported by: simonpj Owned by: simonpj
Priority: normal Milestone:
Component: Template Haskell Version: 6.8.2
Keywords: Cc: marco-oweber@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: TH_reifyMkName
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Marc Weber writes: this doesn't work:

-- packages: template-haskell
{-# OPTIONS_GHC -XTemplateHaskell #-}
module Main where
import Language.Haskell.TH

data A a = A a

type C = A Int

data ABC = ABC Int

$(do
  a <- reify $ mkName "C"
  report False $ show a
  return []
  )
main = print ""

Produces output

|| [1 of 1] Compiling Main             ( test.hs, test.o )
||
test.hs|1| `C' is not in scope at a reify

Using mkName "A" results in

test.hs|1 error|
||     DataConI Main.A (ForallT [a_1627391370] [] (AppT (AppT ArrowT (VarT a_1627391370)) (AppT (ConT Main.A) (VarT a_1627391370)))) Main.A (Fixity 9 InfixL)

as expected

Why do I need it? I'd like to implement kind of very basic relational data representation the way IxSet is doing it but without dynamics..

It will look like this:

type CDs = Table (Autoinc, Artist, Title, Year) -- col types
                 (Artist, Title, Year) -- keys
                 () -- is detail of
type Tracks = Table (Autoinc, Title, RecordingDate)
                    (Title, RecordingDate)
                    (CDs)
$(mkDB ["CDs","Tracks"])

To be able to automatically derive

insert{CDs,Tracks}
delete{CDs,Tracks}
update{CDs,Tracks}

functions I need to get information about those types.. Is this possible?

Thanks Marc Weber

Change History (4)

comment:1 Changed 12 years ago by simonpj

Owner: set to simonpj
Test Case: TH_reifyMkName

Yes, there's a bug here, thank you.

It would certainly be better to say

  reify ''C

as someone pointed out. That is the Right Way. But what you wrote should work too. I'm validating a fix now.

There's still an ambiguity though. If you write

data T = T Int
$( ...reify (mkName "T")...)

then are you expecting the type constructor T or the data constructor T? My fix gives you the type constructor if there is one, and data constructor otherwise. But you can choose by using the quote notation, which is more robust.

Simon

comment:2 Changed 12 years ago by simonpj

Cc: marco-oweber@… added
Resolution: fixed
Status: newclosed
Type: bugmerge

Fixed by

Wed Jun  4 16:02:07 BST 2008  simonpj@microsoft.com
  * Fix Trac #2339: reify (mkName "X")

I don't think this is worth merging to the branch -- we are too close to release, and there's an easy workaround (indeed the workaround is the Right Way).

Simon

comment:3 Changed 11 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:4 Changed 11 years ago by simonmar

Operating System: UnknownUnknown/Multiple
Note: See TracTickets for help on using tickets.