[GHC] #10688: Incorrect program produced, different result with equivalent code

GHC ghc-devs at haskell.org
Mon Jul 27 16:29:08 UTC 2015


#10688: Incorrect program produced, different result with equivalent code
-------------------------------------+-------------------------------------
        Reporter:  Ideophage         |                   Owner:
            Type:  bug               |                  Status:  closed
        Priority:  lowest            |               Milestone:
       Component:  Compiler          |                 Version:  7.10.1
      Resolution:  invalid           |                Keywords:
Operating System:  Linux             |            Architecture:
 Type of failure:  Incorrect result  |  Unknown/Multiple
  at runtime                         |               Test Case:
      Blocked By:                    |                Blocking:
 Related Tickets:                    |  Differential Revisions:
-------------------------------------+-------------------------------------

Comment (by Ideophage):

 Replying to [comment:6 simonpj]:
 > Interesting.  Now that you understand what went wrong, you could write a
 note explaining the trap you fell into, and share it with others.  It is,
 after all, rather surprising when you are told "omit a type signature and
 you get an infinite loop".
 >
 > Simon

 I don't know if it's always the case, but according to my tests, the type
 inferrence algorithm specialize the types without class constraints
 (however, if we enter `:t (unlines . map show)` in GHCi, the polymorphic
 type is inferred). For instance, the following code either prints "1" or
 generates an error depending on whether we comment out or not the
 definition of `print_b` (which is not used) :

 {{{#!hs
 a = (2^64) `div` (2^64) -- 64 or 32
 b = length []

 show' = show

 print_a = print $ show' a
 -- print_b = print $ show' b

 main = print_a
 }}}

 This is because if we apply `show'` to `b`, then the inferred type of
 `show'` becomes `Int → String` (I expected it to be the same as `show`)
 and because we also apply it to `a`, the inferred type of `a` becomes
 `Int`. The « types implication graph » of the code I first gave was more
 complex, but there is nothing more than this involved.

 I thought it was a bug because I assumed GHC's Haskell was referentially
 transparent even without explicit types annotations (so that expanding a
 definition, adding a definition, etc. was not supposed to make a program
 do something else), but I don't know what is feasible.

 The infinite loop is due to the fact that the termination rely on
 arithmetic properties of `Integer`.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10688#comment:7>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list