Skip to content

Allow Newtype deriving for newtypes that use type synonyms #2416

Description

@garyb
No description provided.

Activity

  1. added this to the 1.0 milestone on Nov 3, 2016
  2. paf31 commented on Nov 7, 2016

    @paf31
    Contributor

    This is the same as the corresponding Generic deriving issue, right?

  3. garyb commented on Nov 7, 2016

    @garyb
    MemberAuthor

    I don't know if it is exactly, the error is that you're not allowed to declare instances for type synonyms... is that the same reason it fails there?

  4. paf31 commented on Nov 7, 2016

    @paf31
    Contributor

    Oh I see, then no, it's different.

  5. joshuahhh commented on Dec 13, 2016

    @joshuahhh

    [EDIT: This bug is actually an instance of #2481, a different issue.]

    I think I've run into this bug. My minimal reproduction is

    type MyString = String
    newtype WrappedString = WrappedString MyString
    derive newtype instance semigroupWrappedString :: Semigroup WrappedString
    

    which produces the error

        No type class instance was found for
    
          Data.Semigroup.Semigroup MyString
    
    
      while checking that expression #dict Semigroup
        has type { append :: WrappedString -> WrappedString -> WrappedString
                 }
      in value declaration semigroupWrappedString
    

    even though

    newtype WrappedString = WrappedString String
    derive newtype instance semigroupWrappedString :: Semigroup WrappedString
    

    compiles without error.

    Am I covered by this issue, or is this something different?

    (Thanks!)

  6. joshuahhh commented on Dec 13, 2016

    @joshuahhh

    OK – I just ran into a second, different bug, which actually uses capital-N Newtype deriving. Minimal reproduction is

    type MyString = String
    newtype WrappedString = WrappedString MyString
    derive instance newtypeWrappedString :: Newtype WrappedString _
    

    which produces the error

        Type class instances for type synonyms are disallowed.
    
      in type class instance
    
        Data.Newtype.Newtype WrappedString
                             MyString
    

    even though

    newtype WrappedString = WrappedString String
    derive instance newtypeWrappedString :: Newtype WrappedString _
    

    compiles without error.

    I'm guessing this is the bug referred to by this issue, and the bug I posted yesterday is a different one. Is that right?

    (Thanks even more!)

  7. garyb commented on Dec 13, 2016

    @garyb
    MemberAuthor

    The second one is the case that this is for, yep :)

    The first one might actually be yet another issue though! As it's for lowercase-n newtype deriving.

  8. LiamGoodacre commented on Dec 13, 2016

    @LiamGoodacre
    Member

    Aren't these all the same issue based around when we replace type synonyms?

  9. garyb commented on Dec 13, 2016

    @garyb
    MemberAuthor

    They fall into that general category yeah. But on the other hand I think we shouldn't normally allow instances for type synonyms, to avoid confusion. So we want them to be desugared for deriving, but not for a hand written instance.

  10. adamw commented on Dec 17, 2016

    @adamw

    Just hit the same thing (https://groups.google.com/forum/#!topic/purescript/HG7uiRChNhE). I suppose the same argument as why instances for functionally-dependent record types are allowed would apply to type synonyms?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions