Adding Prim.TypeError.QuoteLabel - #3436
Conversation
| toTypelevelString (TypeApp (TypeConstructor f) x) | ||
| | f == primSubName C.typeError "Quote" = Just (typeAsBox x) | ||
| toTypelevelString (TypeApp (TypeConstructor f) x) | ||
| | f == primSubName C.typeError "QuoteLabel" = Just (typeAsBox x) |
There was a problem hiding this comment.
I think for this, you don't want to use typeAsBox. You want to match directly on TypelevelString for x, along with Just . line . prettyPrintLabel $ x.
| match TypeWildcard{} = Just $ text "_" | ||
| match (TypeVar var) = Just $ text $ T.unpack var | ||
| match (TypeLevelString s) = Just $ text $ T.unpack $ prettyPrintString s | ||
| match (TypeLevelString s) = Just $ text $ T.unpack $ prettyPrintLabel $ Label s |
There was a problem hiding this comment.
With the changes to toTypelevelString, you can revert this. This is definitely not desirable 😄
|
@natefaubion thanks! I fixed toTypelevelString like you suggested, wrote the docs line and moved the test to its own file. |
| quoteLabel :: Declaration | ||
| quoteLabel = primTypeOf (P.primSubName "TypeError") "QuoteLabel" $ T.unlines | ||
| [ "The QuoteLabel type constructor renders any label as a Doc" | ||
| , "to be used in a custom type error." |
There was a problem hiding this comment.
How about
The QuoteLabel type constructor renders any Symbol as a syntactically valid label, escaping with quotes as needed.
|
^ I like mentioning the syntactically valid label stuff. What do you think about?
|
|
Is that ok as the definitive version? :) |
|
I think the only thing is changing the doc text to Liam's suggestion. |
| quoteLabelDoc :: Declaration | ||
| quoteLabelDoc = primTypeOf (P.primSubName "TypeError") "QuoteLabel" $ T.unlines | ||
| [ "The `QuoteLabel` type constructor will produce a `Doc` when given a `Symbol`. When the resulting `Doc` is rendered " | ||
| , "for a `Warn` or `Fail` constraint, a syntactically valid label will be produces, escaping with quotes as needed." |
There was a problem hiding this comment.
Typo: will be produces -> will be produced
There was a problem hiding this comment.
ugh, I even read it 4 times :/ sorry
|
I just noticed that the kindDoc :: Declaration
kindDoc = primKindOf (P.primSubName "TypeError") "Doc" $ T.unlines
[ "`Doc` is the kind of type-level documents."
, ""
, "This kind is used with the `Fail` and `Warn` type clases."
, "Build up a `Doc` with `Text`, `Quote`, `Beside`, and `Above`."
]We should add Could you also add yourself to the I will happily merge once these two things have been updated. |
|
Thank you all for taking the time to review my pr :) |
|
🎉 Thanks again @dariooddenino ! |
This pull request adds
QuoteLabelas described in #3428The test and doc string are obviously placeholders.
Right now it works, but I replaced
prettyPrintStringwithprettyPrintLabelinmatchTypeAtom'smatchforTypeLevelStrings and I suppose this will break other things.I don't think I have a way to discriminate if it's working with a label or not.
matchTypeAtomtakes onlyTypeRenderOptionas argument, but I'm not sure it's appropriate to add a "isLabel" parameter there.