Skip to content

How to derive Show and other classes for Barbies.Bare types #57

@axman6

Description

@axman6

I'm looking at the example of defining a BareB compatible type in Barbies.Bare and the example tantalisingly has the following

data SignUpForm t f
  = SignUpForm
      { username  :: Wear t f String,
      , password  :: Wear t f String
      , mailingOk :: Wear t f Bool
      }
 instance FunctorB (SignUpForm Covered)
 instance TraversableB (SignUpForm Covered)
 ...,
 instance BareB SignUpForm

I'd love to see the ..., filled in to give at least one example of deriving a class like Show or Eq. I've managed to get as far as

data Bareable t f
  = Bareable
    { bareName :: Wear t f String
    , bareAge :: Wear t f Int
    }
  deriving (Generic)

instance BareB Bareable
instance FunctorB (Bareable Covered)
instance TraversableB (Bareable Covered)
instance ApplicativeB (Bareable Covered)
instance DistributiveB (Bareable Covered)

deriving instance AllBF Show f (Bareable Bare) => Show (Bareable Bare f)

but I can't figure out how I'd define an instance for Show (Bareable Covered f) as well. If it's at all interesting, I'm currently working on something which might turn into a package eventually, which provides (hopefully) efficient conversion between Vector (b Identity) and b Vector (including Unboxed vectors where if all fields are compatible) for struct-of-arrays of any Barbie type, and being able to show the result would nice a nice to have.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions