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

Remove Elm instance for String data type #71

Closed
chshersh opened this issue Jul 30, 2019 · 3 comments · Fixed by #83
Closed

Remove Elm instance for String data type #71

chshersh opened this issue Jul 30, 2019 · 3 comments · Fixed by #83
Assignees
Labels
enhancement New feature or request

Comments

@chshersh
Copy link
Contributor

chshersh commented Jul 30, 2019

Because of this instance, it's not possible to derive Elm typeclass for newtype wrappers. I see the following error:

     Overlapping instances for Elm [a]
        arising from the 'deriving' clause of a data type declaration
      Matching instances:
        instance Elm a => Elm [a] -- Defined in ‘Elm.Generic’
        instance [overlapping] Elm String -- Defined in ‘Elm.Generic’
      (The choice depends on the instantiation of a
       To pick the first instance above, use IncoherentInstances
       when compiling the other instance declarations)
     When deriving the instance for (Elm (SqlArray a))
   |
11 |       deriving newtype (Eq, ToJSON, Elm)
   |                                     ^^^
@chshersh chshersh added enhancement New feature or request question Further information is requested labels Jul 30, 2019
@vrom911
Copy link
Contributor

vrom911 commented Jul 30, 2019

Wouldn't OVERLAPPABLE pragma help here?
I don't mind removing the instance if needed 🙂

@chshersh
Copy link
Contributor Author

@vrom911 We already have OVERLAPPABLE pragma 🙂 This is needed because we have instance Elm a => Elm [a] and instance Elm String. But for some unknown reason, if I use newtype deriving strategy for wrappers around [a], GHC cannot decide to choose proper instance... The same problem with the swagger library, the library also has similar instances. So it looks like OVERLAPPABLE breaks automatic deriving.

I also think that you shouldn't use String data type anyway, so I'd instead remove this instance to get nicer interface, rather than supporting rare use case using controversial features...

@chshersh chshersh self-assigned this Sep 3, 2019
@chshersh chshersh changed the title [RFC] Remove Elm instance for String data type? Remove Elm instance for String data type Sep 3, 2019
@chshersh chshersh removed the question Further information is requested label Sep 3, 2019
chshersh added a commit that referenced this issue Sep 3, 2019
vrom911 pushed a commit that referenced this issue Sep 3, 2019
@ShrykeWindgrace
Copy link

ShrykeWindgrace commented Nov 15, 2019

I guess I am very late to the party, but I think that there are valid use cases for passing a (newtype of) String between Elm and Haskell, most notably base64-encoded binary data.

Anyway, I am ok with manually writing newtype Base64 = Base64 String; data Payload = Payload {userId::Int, signature::Base64}; instance Elm Payload =)

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

Successfully merging a pull request may close this issue.

3 participants