You can use the Data.Typeable module

import Data.Typeable

:t typeOf True
typeOf True :: TypeRep

:t show (typeOf True)
show (typeOf True) :: String

typeOf 1 == typeOf 1
True

>typeOf 1 == typeOf True
False

But it works on concrete types, not functions.  Sorry.

let len = sum . map (const 1)
typeOf len

<interactive>:17:1:
    No instance for (Typeable b0) arising from a use of ‘typeOf’
    In the expression: typeOf len
    In an equation for ‘it’: it = typeOf len

On Mon, Mar 7, 2016 at 1:06 PM, Dániel Arató <exitconsole@gmail.com> wrote:
How does GHCi show types?

Is there a magic function (showType :: a -> String) that does that? Or
is this feature buried somewhere deep in the compiler?

Can I show, compare and reason about types in a Haskell program?

This would be cool:

```haskell
test = do
let len = sum . map (const 1)
when (isInfixOf "Integer" (showType len)) $ putStrLn "restrictive type
inferred; maybe try turning off monomorphism restriction"
```
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners