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

Add custom type errors in some places #171

Closed
5 tasks done
chshersh opened this issue Jul 17, 2019 · 1 comment · Fixed by #222
Closed
5 tasks done

Add custom type errors in some places #171

chshersh opened this issue Jul 17, 2019 · 1 comment · Fixed by #222
Assignees
Labels
doc README, Haddock documentation, tutorials enhancement New feature or request

Comments

@chshersh
Copy link
Contributor

chshersh commented Jul 17, 2019

This is a meta-issue to collect all places where custom type errors can be introduced to increase the quality of error messages and make relude more beginner-friendly

  • Foldable1 for ordinary list
  • ToString/ToText/ToLText/ConvertUtf8 for text data types: suggest proper function.
  • head/tail/init/last
  • lines/unlines/words/unwords
  • error

Any other ideas? 🙂

Also, open question: is it worth to add type-errors-pretty to dependencies to write these errors?

@chshersh chshersh added enhancement New feature or request doc README, Haddock documentation, tutorials labels Jul 17, 2019
@chshersh chshersh added this to the v0.6.0.0: Refinement milestone Jul 17, 2019
@chshersh
Copy link
Contributor Author

chshersh commented Oct 3, 2019

Looks like it's possible to have better custom type errors for functions like head, init, tail and last. Using the following code:

type IsNonEmpty (f :: Type -> Type) =
    (f ~ NonEmpty, CheckNonEmpty f)

type family CheckNonEmpty (f :: Type -> Type) :: Constraint where
    CheckNonEmpty NonEmpty = ()
    CheckNonEmpty [] = TypeError ('Text "Should be NonEmpty, not ordinary list")
    CheckNonEmpty _ = TypeError ('Text "Should be NonEmpty list")

head :: IsNonEmpty f => f a -> a
head = NE.head

I didn't expect this work. But looks like it works. We only need to write better error messages)

chshersh pushed a commit that referenced this issue Oct 16, 2019
* [#171] Add custom error to head like functions

* Fix

* Add resulting type in IsNonEmpty type family
vrom911 added a commit that referenced this issue Oct 29, 2019
chshersh pushed a commit that referenced this issue Oct 29, 2019
* [#171] Foldable1 for Lists error

* Update src/Relude/Extra/Foldable1.hs

Co-Authored-By: Dmitrii Kovanikov <kovanikov@gmail.com>

* Fix
vrom911 pushed a commit that referenced this issue Oct 29, 2019
* [#171] Add custom type error for To* typeclasses

* Improve documentation examples
chshersh added a commit that referenced this issue Oct 29, 2019
chshersh added a commit that referenced this issue Oct 29, 2019
chshersh added a commit that referenced this issue Oct 29, 2019
chshersh added a commit that referenced this issue Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc README, Haddock documentation, tutorials enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants