
Hello Julian, Friday, May 14, 2010, 4:18:42 PM, you wrote:
3 + 4 it does not work, and i really don't understand why. If i ask GHCi for 3's type ($ :t 3) it will answer "3 :: (Prelude.Num t) => t". But, if 3 and 4 are Prelude.Nums and there is an instanfe Num x x x for x of Prelude.Num - than why can't GHC deduce from the definitions that 3 and 4, both Prelude.Nums, can be used with (+) since there is an instance for Prelude.Num and my class Num - and
Now, if I type the result will of course be something of Prelude.Num?
because 3 and 4 may have different types. Num is a class, Int is a concrete type. 3 without additional type signature is polymorphic value. usually type inference deduce types of numeric constants (that all are polymorphic) from context but in your case it's impossible your functional dependency allows to fix result type once parameter types are known, but not other way you appeal to *instance* definition but haskell/ghc type inference can't use instance heads to deduce types since classes are open and anyone can add later code that breaks your assumption (imagine that ghc generates code for your module and later this module is imported by someone else and additional instances are provided) btw, quite popular problem, it arrives here each month or so :) there are some ghc pragmas that somewhat break this rule, you may try allow-indecidable-insances or so. but it's dangerous way -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com