[Haskell-beginners] reifying based-on type of a newtype or data
AntC
anthony_clayden at clear.net.nz
Fri Oct 25 09:28:02 UTC 2013
So I have (or rather the user of my package has):
> {-# LANGUAGE DeriveDataTypeable #-}
>
> newtype Foo = Foo Int deriving (Read, Show, Typeable, Data, ...)
> someFoo = Foo Int
>
Note:
* the `newtype` could be `data` -- if that would help.
* this is _not_ a parameterised type, but a 'baked in' `Int`.
* the data constr is named same as the type -- if that would help.
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`)
So far very logical, but not very helpful.
What I want is to get the based-on type baked inside `someFoo`
-- that is: `Int`
(It would also be handy to get the name of the data constr, just in case
it's different to the type.)
Do I need to get into `deriving (..., Generic)` ?
That looks like serious machinery!
Thanks
AntC
More information about the Beginners
mailing list