#89: type inference failure in ghc/hugs extensions ---------------------+------------------------------------------------------ Reporter: guest | Owner: nobody Type: defect | Status: reopened Priority: major | Milestone: Component: hugs | Version: 200609 Resolution: | Keywords: instance extensions ---------------------+------------------------------------------------------ Changes (by guest): * status: closed => reopened * resolution: invalid => Comment: Replying to [comment:1 ross]:
There's an error in the example: should be (a,a) in the instance. If test1 is supplied with a signature, hugs then accepts this (but GHC 6.10 doesn't).
I understand the proposed fix to be essentially as follows, wherein the TypeCast classes become unnecessary {{{ instance Num a => Num (a,a) where (x,y)*(u,v) = (x*u-y*v, x*v+y*u) test1 :: Num a => (a,a) test1 = (1,1)*(2,2) }}} This code is defective in that (a,a) in the instance head does not force the two operands in (x,y) to the same type when (x,y) serves as a Num. The type of test1 cannot be inferred; it has to be declared. (I suspect GHC's rejection of the code is a symptom of the defect.) Oleg's magic was devised precisely to overcome the defect; see the threads http://www.haskell.org/pipermail/haskell/2009-January/020963.html http://www.haskell.org/pipermail/haskell/2009-January/020978.html (Oleg points out that the elaborate TypeCast mechanism can be simplified by using the a~b syntax available in GHC 6.10. I use the elaborate alternative because its syntax is supported more widely.) The bottom line is that Hugs and GHC infer types differently under the "same" type extensions. The difference needs to be sorted out, for the sake of Haskell' if not for me. Barring arcane reasons to the contrary, I incline towards GHC's approach, because it allows the programmer to place more of the burden of type inference on the compiler, so as to unclutter his mind and his code Doug McIlroy doug@cs.dartmouth.edu -- Ticket URL: <http://hackage.haskell.org/trac/hugs/ticket/89#comment:2> Hugs <http://www.haskell.org/hugs/> Hugs 98, an interpreter for Haskell