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 a FromParam instance for String. #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arbuztw
Copy link

@arbuztw arbuztw commented Oct 1, 2017

Fixes #15.

@@ -423,6 +423,10 @@ instance FromParam Text where
fromParam [x] = Right x
fromParam [] = Left ParamMissing
fromParam _ = Left ParamTooMany
instance {-# INCOHERENT #-} FromParam String where
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell me a little more about why "INCOHERENT" is needed here? I've never seen it before.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. The reason is that String is actually [Char] and so GHC complains that it is overlapped with the FromParam [a] instance below. (According to the doc, GHC will not take context (i.e. constrains before =>) into account when matching instances.)
One solution is to add "INCOHERENT" pragma according to this. I am not sure if there is a better solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Let me think a little about whether this feature is worth that extra bit of type complexity. Regardless I appreciate you taking the time to make this PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. Thank you very much!

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

Successfully merging this pull request may close these issues.

2 participants