Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,827
    • Issues 4,827
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 443
    • Merge requests 443
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #4321

Closed
Open
Created Sep 16, 2010 by bjpop@trac-bjpop

Unexpected stack overflow prevented by superfluous type annotation

GHC versions affected:

  • 6.13.20100915
  • 6.13.20090922
  • 6.12.1
  • 6.10.4

OS versions tested:

  • OS X Snow Leopard
  • Ubuntu Linux 9.10 - Karmic Koala

Description:

The attached program computes Pi by integrating 4/(1+x*x) between 0 and 1.

The important line of code is this one:

h * (sum (map area [1..n]))

If you compile the program as it is, with this command:

ghc --make -O2 Pi.hs

it runs out of stack space when run like so:

./Pi 1000000

Stack space overflow: current size 8388608 bytes.
Use `+RTS -Ksize -RTS' to increase it.

For GHC versions 6.10.4, 6.12.1 and 6.13.20090922 However, if you add what appears to be a superfluous type annotation to the line of code, like so:

h * ((sum (map area [1..n])) :: Double)

The program runs to completion with no stack overflow:

./Pi 1000000
3.1415926535897643

Indeed it works just fine for even larger inputs.

However version 6.13.20100915 overflows the stack regardless of whether the type annotation is present or not.

I don't think the type annotation should make any difference to the generated code because GHC should infer that the annotated expression is of type Double anyway (if you put an erroneous type in the same place, GHC complains that it should be a Double).

Edited Mar 09, 2019 by Ian Lynagh <igloo@earth.li>
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking