Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • 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,866
    • Issues 4,866
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 456
    • Merge requests 456
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #21434
Closed
Open
Created Apr 26, 2022 by Richard Eisenberg@raeDeveloper

Explain why a type is defaulted

This comes from https://github.com/haskell/error-messages/issues/56.

In the program

x = 5

GHC will report (with suitable flags)

Scratch.hs:32:5: warning: [-Wtype-defaults]
    * Defaulting the following constraint to type `Integer'
        Num a0 arising from the literal `5'
    * In the expression: 5
      In an equation for `x': x = 5
   |
32 | x = 5
   |     ^

This message leaves out a critical piece of information: why the constraint was defaulted. I suggest

Scratch.hs:32:5: warning: [-Wtype-defaults]
    * Defaulting a0 to type `Integer' to satisfy the following constraint:
        Num a0 arising from the literal `5'
      This constraint could not be part of the context on 'x'
      because of the monomorphism restriction.
    * In the expression: 5
      In an equation for `x': x = 5
   |
32 | x = 5
   |     ^

The new message has several improvements over the existing one:

  1. It is more literally correct. The old message talks about defaulting a constraint to Integer, which doesn't really make sense.
  2. The new message relates the constraint directly to x, which is otherwise somewhat hard to discover.
  3. The new message informs the user that the monomorphism restriction is in play, should they wish to disable it.

Addressing (1) is dead easy: just change the text.

Addressing (2) and (3) is harder: I think the way to do it is to have a new CtOrigin constructor MonomorphismRestrictionOrigin :: CtOrigin -> Id -> CtOrigin that wraps an existing origin so that the above message can be printed. Arranging to create this new CtOrigin is a bit tricky: the place to do it seems to be decideMonoTyVars (which is what deals with the MR), but that would require threading some extra information around.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking