How to get the type of a value in haskell

I'm trying to debug and would like to be able to get a function that returns a value type. Is it possible?

I don't wan't: t, I can't something that can be used in the code


[showType i | i <- [0..5] ]






source to share

2 answers

The class Typeable

encodes each type uniquely at compile time and can be used for this purpose:

import Data.Typeable

showType :: Typeable a => a -> String
showType = show . typeOf


with the result:

*Main> showType (+)
"Integer -> Integer -> Integer"
*Main> showType [1..5]
*Main> map showType [1..5]


All that said, Beclilr is right. What you really want may be something else, so more information will help us help you.



Perhaps you want something like TypedHoles

. This allows you to write in _

place of some expression, and the compiler will tell you what type this hole has or should have.



All Articles