[Haskell-cafe] typeOf for polymorphic value

Roland Zumkeller roland.zumkeller at gmail.com
Fri Mar 27 09:47:00 EDT 2009

Hi Lennart,

This is not a real solution, but maybe helpful. The hint package
(wrapping the ghc API) has its typeOf:

cabal install hint

> import Language.Haskell.Interpreter
> runInterpreter (typeOf "\\x -> x")
Right "t -> t"



On Wed, Mar 25, 2009 at 7:33 PM, Lennart Augustsson
<lennart at augustsson.net> wrote:
> 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
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list