Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 5.5k
    • Issues 5.5k
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 634
    • Merge requests 634
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Model experiments
  • Analytics
    • Analytics
    • 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 CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #19096

Improve error messages when dealing with type level lists

Given this code:

action CreateUserAction = do
        let user = newRecord @User
        let password = param @Text "password"
        user
            |> set #passwordHash password
            |> fill @["email"]
            |> validateField #email isEmail
            |> validateField #passwordHash nonEmpty
            |> debug
            |> ifValid \case
            Left user ->
                render NewView {..}
            Right user -> do
                hashed <- hashPassword (get #passwordHash user)
                user
                    |> set #passwordHash hashed
                    |> createRecord

                setSuccessMessage "You have successfully registered"

GHC errors with:

Web/Controller/Users.hs:16:23
    * Expected a type, but `"email"' has kind `Symbol'
    * In the type `["email"]'
      In the second argument of `(|>)', namely `fill @["email"]'
      In the first argument of `(|>)', namely
        `user |> set #passwordHash password |> fill @["email"]'
   |
16 |             |> fill @["email"]
   |                       ^^^^^^^

Unless you know about the type-level-list syntax issue with ' you will most likely get stuck.

A better error message would be:

Web/Controller/Users.hs:16:23
    * Type level lists with only a single element need a ' in front of the list. Prepend a ' like `'["email]' to get it working.
    * In the type `["email"]'
      In the second argument of `(|>)', namely `fill @["email"]'
      In the first argument of `(|>)', namely
        `user |> set #passwordHash password |> fill @["email"]'
   |
16 |             |> fill @["email"]
   |                       ^^^^^^^

Another alternative suggested on reddit:

Web/Controller/Users.hs:16:23: error: expected kind Type, got Symbol
   |
16 |             |> fill @["email"]
   |                       ^^^^^^^

Did you mean:
* '["email]

(This issue is a followup of https://www.reddit.com/r/haskell/comments/kgvdon/improving_haskell_ghc_error_messages/ :) )

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