jcpetruzza / barbies

BSD 3-Clause "New" or "Revised" License
92 stars 15 forks source link

Template Haskell helper #24

Closed fumieval closed 4 years ago

fumieval commented 4 years ago

I made barbies-th, a wrapper library which generates strippable HKD from a normal definition.

declareBareB [d|
  data Foo = Foo
    { foo :: Int
    , bar :: String
    }  |]

becomes

data Foo sw h = Foo
    { foo :: Wear sw h Int,
    , bar :: Wear sw h String
    } deriving Generic
instance BareB Foo
instance FieldNamesB (Foo Covered) where
  bfieldNames = Foo (Const "foo") (Const "bar")
instance ProductB (Foo Covered) where
  bprod (Foo xfoo xbar) (Foo yfoo ybar)
    = Foo (Pair xfoo yfoo) (Pair xbar ybar)
instance FunctorB (Foo Covered)
instance TraversableB (Foo Covered)
instance ConstraintsB (Foo Covered)
instance ProductBC (Foo Covered)

Are you interested in introducing something like this to barbies? It does add template-haskell dependency, that's why I didn't go forward with a pull request.

jcpetruzza commented 4 years ago

Nice! I think a separate package for TH helpers as you've done is the right approach. There should probably be some a section in the README with pointers to related projects (there's also higgledy). If you have time to make a PR for that, I'd be happy to merge it.

jcpetruzza commented 4 years ago

I added a link to barbies-th from the README

fumieval commented 4 years ago

Oh thanks!