2

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

Benoît Fraikin
  • 584
  • 4
  • 13
  • What's the type of `drawTree`? – Ganesh Sittampalam Jul 09 '14 at 18:27
  • 2
    You sort of have to read everything in the linked duplicate question to get the whole story, but the answer is GHCi 7.6's extended defaulting rules (which extend haskell's numeric defaulting rules), combined with the monomorphism restriction. GHCi 7.8 exhibits the more polymorphic behavior – jberryman Jul 09 '14 at 18:53
  • ok so, this is still a monomorphism problem. Thank you ;) – Benoît Fraikin Jul 09 '14 at 19:44

0 Answers0