[Haskell-cafe] reifying based-on type of a newtype or data

AntC anthony_clayden at clear.net.nz
Tue Oct 29 04:07:49 UTC 2013


> John Lato <jwlato <at> gmail.com> writes:
> 
> What about Data.Typeable.typeRepArgs ?
> typeRepArgs :: TypeRep -> [TypeRep]
> Prelude Data.Data> typeRepArgs (typeOf Foo)[Int,Foo]

Thanks John, I did look at that,
and thought it returned only type args,
not the 'baked in' type.

Your example applies to `(typeOf Foo)` -- that is, the data constr,
which is indeed a function.
And `typeOf Foo` is `Int -> Foo`, as I noted in the OP.

I want something that can apply to a value of type Foo.
(`someFoo`, in my example.)

> ...

> For anything more complicated, I suspect you'll need 
> Data/Generic/Template Haskell.

That is rather what I feared.
I want to avoid TH, because that imposes on my user.

Could you point to where/what in Data/Generics?

> >
> >    newtype Foo = Foo Int    deriving (Read, Show, Typeable, Data, ...)
> >    someFoo     = Foo 7
> >
> > I can ask for `typeOf someFoo` and get `Foo` OK.
> > I can ask for `typeOf Foo`  and get `Int -> Foo` OK.
> > If I ask for `typeOf (typeOf someFoo)` I get `TypeRep`.
> > `typeOf (show $ typeOf someFoo`) gets me `[Char]` (aka `String`)
> > 
> > What I want is to get the based-on type baked inside `someFoo`






More information about the Haskell-Cafe mailing list