
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" ```

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ó
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

But it works on concrete types, not functions.
Isn't the problem type variables, not functions? Prelude Data.Typeable> :set -XScopedTypeVariables Prelude Data.Typeable> let fun x = case x of {Just (i::Int) -> i + 1; Nothing -> 0} Prelude Data.Typeable> :t fun fun :: Maybe Int -> Int Prelude Data.Typeable> typeOf fun Maybe Int -> Int

And you also run into trouble with typeOf Nothing.
On Tue, Mar 8, 2016 at 10:09 AM, Alex Rozenshteyn
But it works on concrete types, not functions.
Isn't the problem type variables, not functions?
Prelude Data.Typeable> :set -XScopedTypeVariables Prelude Data.Typeable> let fun x = case x of {Just (i::Int) -> i + 1; Nothing -> 0} Prelude Data.Typeable> :t fun fun :: Maybe Int -> Int Prelude Data.Typeable> typeOf fun Maybe Int -> Int
participants (3)
-
Alex Rozenshteyn
-
David McBride
-
Dániel Arató