Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,326
    • Issues 4,326
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 390
    • Merge Requests 390
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #19098

Closed
Open
Opened Dec 21, 2020 by Marc Scholten@mpscholten

Improve error messages of implicit parameter constraints

In IHP we're passing lot's of state around using implicit parameters. Often times when users are extracting out functionality into their own functions, they'll get an error because some implicit parameter constraint is missing. It would improve the UX a lot when we could suggest the user to add the constraint to the type signature like below.

Also it might be good to specifically mention the word implicit parameter because some people wonder what a variable with ? in front is about, but it's not very google friendly. When we have implicit parameter inside the error message it might be easier to learn about implicit parameters and get a better understanding.

Given this code:

fetchCategories :: (?modelContext :: ModelContext) => IO ()
fetchCategories = do
  categories :: [Category] <- query @Category |> fetch
  putContext categories

GHC errors with:

Web/FrontController.hs:18:3: error:
    * Could not deduce: ?context::ControllerContext
        arising from a use of `putContext'
      from the context: ?modelContext::ModelContext
        bound by the type signature for:
                   fetchCategories :: (?modelContext::ModelContext) => IO ()
        at Web/FrontController.hs:15:1-59
    * In a stmt of a 'do' block: putContext categories
      In the expression:
        do categories :: [Category] <- query @Category |> fetch
           putContext categories
      In an equation for `fetchCategories':
          fetchCategories
            = do categories :: [Category] <- query @Category |> fetch
                 putContext categories
   |
18 |   putContext categories

A better error message would be:

Web/FrontController.hs:18:3: error:
    * The call to `putContext` requires an implicit parameter `?context::ControllerContext` to be available. Change the type signature to this: fetchCategories :: (?modelContext::ModelContext, ?context :: ControllerContext) => IO ()
        at Web/FrontController.hs:15:1-59
    * In a stmt of a 'do' block: putContext categories
      In the expression:
        do categories :: [Category] <- query @Category |> fetch
           putContext categories
      In an equation for `fetchCategories':
          fetchCategories
            = do categories :: [Category] <- query @Category |> fetch
                 putContext categories
   |
18 |   putContext categories
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#19098