OK, now I get it. I'm copying the TH list in the hope that other TH aficionados will chime in. The problem is with reify, not the '' notation. Here it is in a nutshell: what value should be returned by the call (reify ''(->) )? Recall that reify :: Name -> Q Info So reify claims to return an Info, and for a type constructor it currently returns a TyConI; but a TyConI contains a Dec, and there simply is no Dec in the TH syntax for a function type; it's built in, rather like Int# etc. So reify falls over in a bad way. It's obviously unsatisfactory for reify to just fall over in this case, but what would you like? A new constructor in Info for primitive tycons? A new constructor in Dec? And what questions do you want to be able to ask of the value in the Info? For example would it be enough to day data Info = TyConI Dec | PrimTyCon | ClassI Dec ...etc... where the PrimTyCon is returned for (->), Int#, etc? Nothing difficult about fixing this once the design is clear. Simon | -----Original Message----- | From: Keean Schupke [mailto:k.schupke@imperial.ac.uk] | Sent: 27 October 2004 11:14 | To: Simon Peyton-Jones | Subject: Re: TH2 bug | | Yup, using HEAD. Here's an example template: | | ttypeshow :: Name -> Q [Dec] | ttypeshow q = do | r <- reify q | case r of | (TyConI t) -> runIO . putStrLn . show $ t | _ -> return () | return [] | | Then in another file we do: | | $(ttypeshow ''(->)) | | Which fails, as does ''(), and ''(,) etc... | | ''[] works okay however | | Keean. | | | Simon Peyton-Jones wrote: | | >I can't reproduce this. Works for me. What version of GHC are you | >using? The HEAD I assume? | > | >Simon | > | >| -----Original Message----- | >| From: MR K P SCHUPKE [mailto:k.schupke@imperial.ac.uk] | >| Sent: 22 October 2004 18:23 | >| To: glasgow-haskell-users@haskell.org; Simon Peyton-Jones | >| Subject: TH2 bug | >| | >| | >| Just reporting a bug, taking types using '' works fine for: | >| | >| ''Int | >| ''[] | >| | >| But when you try: | >| | >| ''(->) | >| | >| you get: | >| | >| No match in record selector TyCon.algTcRhs | >| | >| Please report it as a compiler bug to | >glasgow-haskell-bugs@haskell.org, | >| or http://sourceforge.net/projects/ghc/. | >| | >| | >| Keean. | > | >
Actually I would like it to be a special name... but I guess there are other possibilities. Ideally I would like: case info of (PrimTyCon name) -> instanceD (cxt []) (appT (conT classname) (appT (appT (conT name) (varT a) (varT b))) to generate: instance ClassName (a -> b) Keean Simon Peyton-Jones wrote:
OK, now I get it. I'm copying the TH list in the hope that other TH aficionados will chime in.
The problem is with reify, not the '' notation. Here it is in a nutshell:
what value should be returned by the call (reify ''(->) )?
Recall that reify :: Name -> Q Info
So reify claims to return an Info, and for a type constructor it currently returns a TyConI; but a TyConI contains a Dec, and there simply is no Dec in the TH syntax for a function type; it's built in, rather like Int# etc. So reify falls over in a bad way.
It's obviously unsatisfactory for reify to just fall over in this case, but what would you like? A new constructor in Info for primitive tycons? A new constructor in Dec?
And what questions do you want to be able to ask of the value in the Info? For example would it be enough to day
data Info = TyConI Dec | PrimTyCon | ClassI Dec ...etc...
where the PrimTyCon is returned for (->), Int#, etc?
Nothing difficult about fixing this once the design is clear.
Simon
| -----Original Message----- | From: Keean Schupke [mailto:k.schupke@imperial.ac.uk] | Sent: 27 October 2004 11:14 | To: Simon Peyton-Jones | Subject: Re: TH2 bug | | Yup, using HEAD. Here's an example template: | | ttypeshow :: Name -> Q [Dec] | ttypeshow q = do | r <- reify q | case r of | (TyConI t) -> runIO . putStrLn . show $ t | _ -> return () | return [] | | Then in another file we do: | | $(ttypeshow ''(->)) | | Which fails, as does ''(), and ''(,) etc... | | ''[] works okay however | | Keean. | | | Simon Peyton-Jones wrote: | | >I can't reproduce this. Works for me. What version of GHC are you | >using? The HEAD I assume? | > | >Simon | > | >| -----Original Message----- | >| From: MR K P SCHUPKE [mailto:k.schupke@imperial.ac.uk] | >| Sent: 22 October 2004 18:23 | >| To: glasgow-haskell-users@haskell.org; Simon Peyton-Jones | >| Subject: TH2 bug | >| | >| | >| Just reporting a bug, taking types using '' works fine for: | >| | >| ''Int | >| ''[] | >| | >| But when you try: | >| | >| ''(->) | >| | >| you get: | >| | >| No match in record selector TyCon.algTcRhs | >| | >| Please report it as a compiler bug to | >glasgow-haskell-bugs@haskell.org, | >| or http://sourceforge.net/projects/ghc/. | >| | >| | >| Keean. | > | >
Just checked and 'Type' has an entry (ArrowT) for functions. Why not just use the existing Type. IE reify ''(->) data Info = PrimTyCon Type TyConI Dec This would be fine for tuples as well, I wonder if () could be encoded as a tuple of 0? Keean. Keean Schupke wrote:
Actually I would like it to be a special name... but I guess there are other possibilities.
Ideally I would like:
case info of (PrimTyCon name) -> instanceD (cxt []) (appT (conT classname) (appT (appT (conT name) (varT a) (varT b)))
to generate:
instance ClassName (a -> b)
Keean
Simon Peyton-Jones wrote:
OK, now I get it. I'm copying the TH list in the hope that other TH aficionados will chime in.
The problem is with reify, not the '' notation. Here it is in a nutshell: what value should be returned by the call (reify ''(->) )?
Recall that reify :: Name -> Q Info
So reify claims to return an Info, and for a type constructor it currently returns a TyConI; but a TyConI contains a Dec, and there simply is no Dec in the TH syntax for a function type; it's built in, rather like Int# etc. So reify falls over in a bad way.
It's obviously unsatisfactory for reify to just fall over in this case, but what would you like? A new constructor in Info for primitive tycons? A new constructor in Dec? And what questions do you want to be able to ask of the value in the Info? For example would it be enough to day
data Info = TyConI Dec | PrimTyCon | ClassI Dec ...etc...
where the PrimTyCon is returned for (->), Int#, etc?
Nothing difficult about fixing this once the design is clear.
Simon
| -----Original Message----- | From: Keean Schupke [mailto:k.schupke@imperial.ac.uk] | Sent: 27 October 2004 11:14 | To: Simon Peyton-Jones | Subject: Re: TH2 bug | | Yup, using HEAD. Here's an example template: | | ttypeshow :: Name -> Q [Dec] | ttypeshow q = do | r <- reify q | case r of | (TyConI t) -> runIO . putStrLn . show $ t | _ -> return () | return [] | | Then in another file we do: | | $(ttypeshow ''(->)) | | Which fails, as does ''(), and ''(,) etc... | | ''[] works okay however | | Keean. | | | Simon Peyton-Jones wrote: | | >I can't reproduce this. Works for me. What version of GHC are you | >using? The HEAD I assume? | > | >Simon | > | >| -----Original Message----- | >| From: MR K P SCHUPKE [mailto:k.schupke@imperial.ac.uk] | >| Sent: 22 October 2004 18:23 | >| To: glasgow-haskell-users@haskell.org; Simon Peyton-Jones | >| Subject: TH2 bug | >| | >| | >| Just reporting a bug, taking types using '' works fine for: | >| | >| ''Int | >| ''[] | >| | >| But when you try: | >| | >| ''(->) | >| | >| you get: | >| | >| No match in record selector TyCon.algTcRhs | >| | >| Please report it as a compiler bug to | >glasgow-haskell-bugs@haskell.org, | >| or http://sourceforge.net/projects/ghc/. | >| | >| | >| Keean. | > | >
_______________________________________________ template-haskell mailing list template-haskell@haskell.org http://www.haskell.org/mailman/listinfo/template-haskell
On Wed, Oct 27, 2004 at 02:19:57PM +0100, Simon Peyton-Jones wrote:
And what questions do you want to be able to ask of the value in the Info? For example would it be enough to day
data Info = TyConI Dec | PrimTyCon | ClassI Dec ...etc...
where the PrimTyCon is returned for (->), Int#, etc?
Being able to tell whether it is a lifted type or not might be useful, so you know not to go making class instances of Int#. Also it may be useful to know that (->) takes 2 types as arguments. Maybe PrimTyCon Bool{-unlifted-} Name [Name] (i.e. DataD with all the stuff that doesn't occur removed)? In fact, we could just have (DataD [] name names [] []), but I think I prefer the above as it makes it clear you can't tweak it a bit and splice it in (and gives a place to say "unlifted"). Incidentally, ghci seems to be running the contents of splices twice: Prelude Language.Haskell.TH> $( do runIO $ putStrLn "Foo"; return (LitE (IntegerL 5)) ) Foo Foo 5 Prelude Language.Haskell.TH> Thanks Ian
participants (3)
-
Ian Lynagh -
Keean Schupke -
Simon Peyton-Jones