Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write custom type-errors #7

Open
chshersh opened this issue Mar 20, 2021 · 4 comments
Open

Write custom type-errors #7

chshersh opened this issue Mar 20, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@chshersh
Copy link
Contributor

Currently the default GHC errors are produced, but we can do better with custom type errors. Probably even using the type-errors-pretty library.

@chshersh chshersh added the enhancement New feature or request label Mar 20, 2021
@JonathanLorimer
Copy link

I'd be interested in helping out with this. I will have some time to put into this next week. I am just learning about custom type errors in Thinking With Types. Is there a small place that would be good for me to start on?

@chshersh
Copy link
Contributor Author

chshersh commented Apr 2, 2021

@JonathanLorimer A good starting point would be to patch the runEIO function:

eio/src/EIO.hs

Lines 65 to 66 in 4a09370

runEIO :: EIO '[] () -> IO ()
runEIO = coerce

So instead of simply checking for an empty type-level list of exceptions, we can write a better custom error message in the spirit:

The 'runEIO' handler requires to handle all exceptions in 'EIO'.
But the action throws the following exceptions:

    * MyErr1
    * MyErr2

@JonathanLorimer
Copy link

JonathanLorimer commented Apr 3, 2021

I would like to use type-errors-pretty as you mentioned, but it is built with stack, which has 8.10.4 as its latest ghc version and eio uses 9.0.1. I am not sure if the compiler mismatch is a fatal error, but cabal is unable to solve the version constraints on base:

  -- eio.cabal
  build-depends:       base ^>= 4.15.0.0,

  -- type-errors-pretty.cabal
  build-depends:       base >= 4.10.1.0 && < 4.15

I am not really sure how to move a stack project beyond the nightly lts. Perhaps my first pass should just use the type error functions in GHC.TypeLits

@JonathanLorimer
Copy link

Alright, I put together a preliminary PR #13 . I tried to follow the style of your previous commits, but let me know if there is a CONTRIBUTING.md guide somewhere that I can follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants