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,823
    • Issues 4,823
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 446
    • Merge requests 446
  • 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
  • #20418

Closed
Open
Created Sep 26, 2021 by Jaro Reinders@NoughtmareDeveloper

The () constraint should perhaps not be optimised.

Summary

Optimising the constraint () away can change the behavior of programs. Sometimes you want to use global variables that are recomputed each time they are used, because storing the entire structure takes too much space.

Steps to reproduce

x :: () => [Int]
x = [0..]

main = do
  print $ x !! 1000000000
  print $ x !! 1000000001

Expected behavior

This program should run in constant memory because the list [0..] should be recomputed.

To get the expected behavior we have to trick the compiler with a more complicated constraint like:

x :: ()~() => [Int]

or

x :: (() :: Constraint) => [Int]

But what if GHC also optimises these away in the future?

Environment

  • GHC version used: 8.10.4
Edited Sep 26, 2021 by Jaro Reinders
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking