
On Tue, Oct 4, 2011 at 1:33 PM, Karel Gardas
Hello,
thanks a lot to Edward, Jose, Ryan and Stephen for fast reply in this thread. I see I've not been that precise in specification of what I need exactly so I need to add this: I've changed a little bit definition of person to:
data PersonType = Person { id :: Int , name :: String , email :: Maybe String } deriving (Show, Data, Typeable)
so I have `PersonType' as type constructor and Person as value constructor (or data constructor) -- speaking using terms from Real World Haskell, Chapter 3[1]. And now I see that none of typeOf/dataTypeOf/toContr is applicable to *type constructor* but all are applicable to *value/data constructor*. Ditto happen when testing Color versus RED, GREEN, BLUE. At least GHCi complains this way:
*Main> typeOf Color
<interactive>:0:8: Not in scope: data constructor `Color' *Main> typeOf PersonType
<interactive>:0:8: Not in scope: data constructor `PersonType'
But, I'd like to start processing of data definition from the *type constructor*. So:
emit_proto PersonType 1 emit_proto Color 1
You could use Data.Proxy and pass a type proxy as the first argument:
emit_proto (Proxy :: Proxy MyType) 1
It seems like you could then do something like `dataTypeOf (asProxyTypeOf undefined proxy)` to unpack the 'Data' instance of the proxied type. There might be a better way, but this is just what I can think of off the top of my head. The 'Poxy' type is here: http://hackage.haskell.org/packages/archive/tagged/0.2.3.1/doc/html/Data-Pro... Antoine