How to get the type of a value in haskell
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]
"[Integer]"
*Main> map showType [1..5]
["Integer","Integer","Integer","Integer","Integer"]
All that said, Beclilr is right. What you really want may be something else, so more information will help us help you.
+8
source to share
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.
+4
source to share