[Haskell-cafe] typeOf for polymorphic value
Lennart Augustsson
lennart at augustsson.net
Wed Mar 25 19:33:43 EDT 2009
Using Data.Typeable.typeOf we can get a representation of the the type
of a monomorphic value, for instance
Prelude Data.Typeable> typeOf not
Bool -> Bool
But if we try using it on a polymorphic value it fails
Prelude Data.Typeable> typeOf id
<interactive>:1:0:
Ambiguous type variable `a' in the constraint:
`Typeable a' arising from a use of `typeOf' at <interactive>:1:0-8
Probable fix: add a type signature that fixes these type variable(s)
And understandably so. Does anyone know of a trick to accomplish `typeOf id'?
Using something else than TypeRep as the representation, of course.
Any tricks and existing language extensions are welcome.
(As ghc moves towards first class polymorphic values this question
gets more interesting.)
-- Lennart
More information about the Haskell-Cafe
mailing list