Can I reify types?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Can I reify types?

Marc Weber
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 ""


|| [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
_______________________________________________
template-haskell mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/template-haskell
Reply | Threaded
Open this post in threaded view
|

Re: Can I reify types?

Bugzilla from alfonso.acosta@gmail.com
On Sun, May 25, 2008 at 5:19 PM, Marc Weber <[hidden email]> wrote:
> This doesn't work:

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

Whenever you can avoid using mkName and provide the Name directly
using single quotes, in this case ...

$(do
  a <- reify ''C
  report False $ show a
  return []
 )

... would do. Note that a preceeding souble single quote is ('') used
for type constructors whereas a single quote (') is used for data
constructors.


> main = print ""
>
>
> || [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
> _______________________________________________
> template-haskell mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/template-haskell
>
_______________________________________________
template-haskell mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/template-haskell
Reply | Threaded
Open this post in threaded view
|

Re: Can I reify types?

Bugzilla from alfonso.acosta@gmail.com
On Sun, May 25, 2008 at 5:57 PM, Alfonso Acosta
<[hidden email]> wrote:
> Whenever you can avoid using mkName and provide the Name directly
> using single quotes, in this case ...

Sorry for the typo. I meant "you should avoid using mkName whenever possible"
_______________________________________________
template-haskell mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/template-haskell
Reply | Threaded
Open this post in threaded view
|

RE: Can I reify types?

Simon Peyton Jones
In reply to this post by Marc Weber
See http://hackage.haskell.org/trac/ghc/ticket/2339

Simon


| -----Original Message-----
| From: [hidden email] [mailto:[hidden email]] On Behalf Of
| Marc Weber
| Sent: 25 May 2008 16:19
| To: [hidden email]
| Subject: [Template-haskell] Can I reify types?
|
| 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 ""
|
|
| || [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
| _______________________________________________
| template-haskell mailing list
| [hidden email]
| http://www.haskell.org/mailman/listinfo/template-haskell

_______________________________________________
template-haskell mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/template-haskell