packages feed

barbies-th 0 → 0.1

raw patch · 4 files changed

+64/−13 lines, 4 filesdep ~barbiesPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: barbies

API changes (from Hackage documentation)

Files

+ README.md view
@@ -0,0 +1,41 @@+barbies-th+====++[![Hackage](https://img.shields.io/hackage/v/barbies-th.svg)](https://hackage.haskell.org/package/barbies-th)+![Haskell CI](https://github.com/fumieval/barbies-th/workflows/Haskell%20CI/badge.svg)++A wrapper library for [barbies](http://hackage.haskell.org/package/barbies) to generate [strippable HKD](http://hackage.haskell.org/package/barbies-1.1.3.0/docs/Data-Barbie-Bare.html)s. It transforms the following declaration++```haskell+declareBareB [d|+  data Foo = Foo+    { foo :: Int+    , bar :: String+    }  |]+```++into:++```haskell+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) where ...+instance TraversableB (Foo Covered) where ...+instance ConstraintsB (Foo Covered)+instance ProductBC (Foo Covered)+```++GHC sometimes takes very long time to compile code with generically derived instances, and it often fails to inline functions properly too. This package generates most instance methods by TH, reducing large amount of compilation time+of the declarations and use sites.++Unlike [higgledy](https://hackage.haskell.org/package/higgledy) which relies on+in-memory representation using `GHC.Generic`, you don't have to worry about the performance, and you can benefit from various language features+(e.g. -Wmissing-fields, `RecordWildCards` etc) even in higher-kinded form.
barbies-th.cabal view
@@ -1,6 +1,6 @@ cabal-version:       2.4 name:                barbies-th-version:             0+version:             0.1 synopsis:            Create strippable HKD via TH description:         Please see Data.Barbie.TH bug-reports:         https://github.com/fumieval/barbies-th@@ -10,14 +10,14 @@ maintainer:          fumiexcel@gmail.com copyright:           Copyright (c) 2019 Fumiaki Kinoshita category:            Data, Generics-extra-source-files:  CHANGELOG.md+extra-source-files:  CHANGELOG.md, README.md  library   exposed-modules:     Data.Barbie.TH   other-extensions:    RankNTypes, PolyKinds, DataKinds, KindSignatures, TemplateHaskell, TypeFamilies   build-depends:       base >= 4.12     , template-haskell >= 2.14 && <2.16-    , barbies+    , barbies ^>= 2.0   hs-source-dirs:      src   default-language:    Haskell2010   ghc-options: -Wall
src/Data/Barbie/TH.hs view
@@ -17,8 +17,8 @@ import Language.Haskell.TH.Syntax (VarBangType) import Data.String import Data.Foldable (foldl')-import Data.Barbie-import Data.Barbie.Bare+import Barbies+import Barbies.Bare import Data.Functor.Product import GHC.Generics (Generic) import Control.Applicative@@ -30,8 +30,8 @@   bfieldNames :: IsString a => b (Const a)  -- | Transform a regular Haskell record declaration into HKD form.--- 'BareB', 'FieldNamesB', 'FunctorB', 'TraversableB', 'ProductB',--- 'ConstraintsB' and 'ProductBC' instances are derived.+-- 'BareB', 'FieldNamesB', 'FunctorB', 'TraversableB', 'ApplicativeB' and+-- 'ConstraintsB' instances are derived. -- -- For example, --@@ -54,9 +54,20 @@       let ys = varNames "y" fields       let transformed = transformCon varS varW con       let names = foldl' AppE (ConE conName) [AppE (ConE 'Const) $ AppE (VarE 'fromString) $ LitE $ StringL $ nameBase name | (name, _, _) <- fields]-      let datC = conT dataName `appT` conT ''Covered++          -- Turn TyVarBndr into just a Name such that we can+          -- reconstruct the constructor applied to already-present+          -- type variables below.+          varName (PlainTV n) = n+          varName (KindedTV n _) = n++          -- The type name as present originally along with its type+          -- variables.+          vanillaType = foldl' appT (conT dataName) (varT . varName <$> tvbs)++      let datC = vanillaType `appT` conT ''Covered       decs <- [d|-        instance BareB $(conT dataName) where+        instance BareB $(vanillaType) where           bcover $(conP conName $ map varP xs) = $(foldl'               appE               (conE conName)@@ -84,8 +95,7 @@             )           {-# INLINE btraverse #-}         instance ConstraintsB $(datC)-        instance ProductBC $(datC)-        instance ProductB $(datC) where+        instance ApplicativeB $(datC) where           bprod $(conP conName $ map varP xs) $(conP conName $ map varP ys) = $(foldl'             (\r (x, y) -> [|$(r) (Pair $(varE x) $(varE y))|])             (conE conName) (zip xs ys))
tests/Main.hs view
@@ -8,8 +8,8 @@ module Main where import Data.Barbie.TH import GHC.Generics-import Data.Barbie-import Data.Barbie.Bare+import Barbies+import Barbies.Bare declareBareB [d|   data Foo = Foo     { foo :: Int