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,869
    • Issues 4,869
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 455
    • Merge requests 455
  • 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
  • #19098
Closed
Open
Created 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
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking