[Haskell-cafe] The Haskell type inference feature I'd really like to see

John Meacham john at repetae.net
Fri Oct 24 17:00:54 EDT 2008

On Fri, Oct 24, 2008 at 01:38:23PM -0700, Dan Piponi wrote:
> I'd like to be able to write something like
> > map zipWith ([1,2,3] >>= printMyInferredType)
> and have the compiler treat 'printMyInferredType' as undefined, but
> also produce the side effect of printing out its inferred type.
> What's the easiest way to simulate this with what we have now?

This will work as long as your type has a typeable instance. You can
modify it to work in an non-io context with unsafePerformIO (as long as
you are aware of the caveats of doing so)

import Data.Typeable

printInferedType :: Typeable a => a -> IO ()
printInferedType x = print (typeOf x)

main = do
    printInferedType ()
    printInferedType "foo"    

John Meacham - ⑆repetae.net⑆john⑈

More information about the Haskell-Cafe mailing list