cabal-version: 3.0 name: stock version: 0.1.0.0 synopsis: Stock-style deriving via coercion, with no Generic x-revision: 14 description: A GHC type-checker plugin that derives class instances for __@@__ and higher-kinded variants at /compile time/, straight from the structure of /T/ without a @Generic@ representation or runtime cost. Synthesized instances emulate GHC's /stock/ deriving. Supported classes: * __@@__: @@, @@, @@, @@, @@, @@, @@, @@, @@, @@ * __@@__: @@, @@, @@,† @@, @@, @@, @@, @@, @@, @@, @@, @@ * __@@__: @@, @@, @@,† @@, @@, @@, @@, @@ † @@, @@ are synthesisable but cannot be used with @DerivingVia@ due to role issues. Companion packages add more classes through @DeriveStock@ instances (see "Stock.Derive"), discovered automatically without an extra @-fplugin@ flag: * __@@__: @@, @@, @@ * __@@__: @@, @@, @@ * __@@__: @@, @@, @@; @@, @@, @@ * __@@__: @@, @@, @@; @@ * __@@__: @@ Ordinary @DerivingVia@ modifiers compose with : * @@ reverses ordering, enumeration and bounds * @@ reverses @@ effects * @@ reverses @@ \/ @@ > {-# options_ghc -fplugin Stock #-} > {-# language DerivingVia #-} > > import Stock > import Data.Ord (Down(..)) > > -- >>> sort [Bronze,Silver,Gold] > -- [Gold,Silver,Bronze] > data Place = Bronze | Silver | Gold > deriving (Eq, Show) via Stock Place > deriving (Ord, Bounded, Enum) via Down (Stock Place) Per-field modifiers (@Override@, "Stock.Override", re-exported by "Stock") customise individual fields by name, type, or position; @_@ leaves a field unchanged. A modifier is any newtype with the relevant instance. This game example shows hit points and coins accumulate with addition, poisoning contaminates by disjunction (or), @items@, and @weapons@ union with addition to produce a multiset. > import Data.Map.Monoidal (MonoidalMap(..)) > > type MultiSet key = MonoidalMap key (Sum Int) > > data Inventory = Inventory > { hp :: Int -- (+) > , coins :: Int -- (+) > , poisoned :: Bool -- (||) > , items :: Map Item Int -- unionWith (+) > , weapons :: Map Weapon Int -- unionWith (+) > } > deriving (Eq, Ord, Show, Read) via > Stock Inventory > deriving (Semigroup, Monoid) via > Overriding Inventory > '[ hp via Sum > , coins via Sum > , poisoned via Any > , items via MultiSet Item > , weapons via MultiSet Weapon > ] Synthesis runs once per instance (not per use): @deriving Cls via Stock T@ produces a single shared @instance Cls T@ that every call reuses. license: BSD-3-Clause license-file: LICENSE author: Baldur Blöndal maintainer: baldur.blondal@iohk.io category: Type System build-type: Simple tested-with: GHC >= 9.6 && < 9.15 , GHC == 9.6.7 , GHC == 9.8.1, GHC == 9.8.2, GHC == 9.8.4 , GHC == 9.10.1, GHC == 9.10.2, GHC == 9.10.3 , GHC == 9.12.1, GHC == 9.12.2, GHC == 9.12.4 , GHC == 9.14.1 extra-doc-files: README.md CHANGELOG.md extra-source-files: LICENSE common warnings ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints default-language: GHC2021 library import: warnings exposed-modules: Stock Stock.Type Stock.Derive Stock.Override Stock.Surface Stock.Internal Stock.Compat Stock.Bounded Stock.Eq Stock.Ord Stock.Semigroup Stock.Show Stock.Read Stock.Enum Stock.Functor Stock.Applicative Stock.Traversable Stock.TestEquality Stock.Bifunctor Stock.Generic Stock.Classes1 other-modules: Stock.Trans build-depends: base >=4.18 && <5, ghc >=9.6 && <9.16 hs-source-dirs: src plugin test-suite examples import: warnings type: exitcode-stdio-1.0 main-is: Main.hs other-modules: QualOverride build-depends: base >=4.18 && <5, transformers < 0.7, stock ghc-options: -fplugin=Stock hs-source-dirs: examples test-suite spec import: warnings type: exitcode-stdio-1.0 main-is: Spec.hs other-modules: Twin build-depends: base >=4.18 && <5, stock ghc-options: -fplugin=Stock hs-source-dirs: test benchmark bench import: warnings type: exitcode-stdio-1.0 main-is: Bench.hs build-depends: base >=4.18 && <5, stock ghc-options: -O2 -rtsopts "-with-rtsopts=-K512m" -fplugin=Stock hs-source-dirs: bench benchmark configs import: warnings type: exitcode-stdio-1.0 main-is: Configs.hs build-depends: base, stock ghc-options: -O2 -fplugin=Stock hs-source-dirs: bench test-suite inspection type: exitcode-stdio-1.0 main-is: Inspection.hs build-depends: base, stock, inspection-testing ghc-options: -fplugin=Stock hs-source-dirs: inspection default-language: GHC2021 if impl(ghc >= 9.14) buildable: False source-repository head type: git location: https://github.com/Icelandjack/stock.git