Greeting,
I am a little surprised that I get two different type in GHCi with the same expression whether I bind it or not. I defined a function to print Tree in a user friendly format with the drawTree with this
let printTree = putStrLn . drawTree . fmap show
The inferred type is Show a => Tree () -> IO ()
. This is not what I was expected. So I tried to type directly the body of printTree
. Indeed, this gave me the expected type
putStrLn . drawTree . fmap show :: Show a => Tree a -> IO ()
I know that I can define printTree
with $
or with a parameter to avoid this problem. However, I wonder why GHCi doesn't get the same type.
Can someone explain me this behavior ? Thank you