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/ :) )