packages feed

stock-0.1.0.2: stock.cabal

cabal-version:       3.0
name:                stock
version:             0.1.0.2
synopsis:            Stock-style deriving via coercion, with no Generic
description:
  A GHC type-checker plugin that derives class instances for
  __@<https://hackage-content.haskell.org/package/stock-0.1.0.2/docs/Stock.html#t:Stock Stock T>@__ 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:

  * __@<https://hackage-content.haskell.org/package/stock-0.1.0.2/docs/Stock.html#t:Stock Stock>@__: @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Eq.html#t:Eq Eq>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Ord.html#t:Ord Ord>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Text-Show.html#t:Show Show>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Text-Read.html#t:Read Read>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Semigroup.html#t:Semigroup Semigroup>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Monoid.html#t:Monoid Monoid>@,
    @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Prelude.html#t:Enum Enum>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Prelude.html#t:Bounded Bounded>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Ix.html#t:Ix Ix>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/GHC-Generics.html#t:Generic Generic>@
  * __@<https://hackage-content.haskell.org/package/stock-0.1.0.2/docs/Stock.html#t:Stock1 Stock1>@__: @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Functor.html#t:Functor Functor>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Foldable.html#t:Foldable Foldable>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Traversable.html#t:Traversable Traversable>@,† @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Functor-Contravariant.html#t:Contravariant Contravariant>@,
    @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Control-Applicative.html#t:Applicative Applicative>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Functor-Classes.html#t:Eq1 Eq1>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Functor-Classes.html#t:Ord1 Ord1>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Functor-Classes.html#t:Show1 Show1>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Functor-Classes.html#t:Read1 Read1>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/GHC-Generics.html#t:Generic1 Generic1>@,
    @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Type-Equality.html#t:TestEquality TestEquality>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Type-Coercion.html#t:TestCoercion TestCoercion>@
  * __@<https://hackage-content.haskell.org/package/stock-0.1.0.2/docs/Stock.html#t:Stock2 Stock2>@__: @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Bifunctor.html#t:Bifunctor Bifunctor>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Bifoldable.html#t:Bifoldable Bifoldable>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Bitraversable.html#t:Bitraversable Bitraversable>@,† @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Functor-Classes.html#t:Eq2 Eq2>@,
    @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Functor-Classes.html#t:Ord2 Ord2>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Functor-Classes.html#t:Show2 Show2>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Functor-Classes.html#t:Read2 Read2>@, @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Control-Category.html#t:Category Category>@

  † @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Traversable.html#t:Traversable Traversable>@, 
  @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Bitraversable.html#t:Bitraversable Bitraversable>@ 
  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:

  * __@<https://hackage.haskell.org/package/stock-deepseq stock-deepseq>@__: @<https://hackage-content.haskell.org/package/deepseq-1.5.2.0/docs/Control-DeepSeq.html#t:NFData NFData>@, @<https://hackage-content.haskell.org/package/deepseq-1.5.2.0/docs/Control-DeepSeq.html#t:NFData1 NFData1>@, @<https://hackage-content.haskell.org/package/deepseq-1.5.2.0/docs/Control-DeepSeq.html#t:NFData2 NFData2>@
  * __@<https://hackage.haskell.org/package/stock-hashable stock-hashable>@__: @<https://hackage-content.haskell.org/package/hashable-1.5.1.0/docs/Data-Hashable.html#t:Hashable Hashable>@, @<https://hackage-content.haskell.org/package/hashable-1.5.1.0/docs/Data-Hashable-Lifted.html#t:Hashable1 Hashable1>@, @<https://hackage-content.haskell.org/package/hashable-1.5.1.0/docs/Data-Hashable-Lifted.html#t:Hashable2 Hashable2>@
  * __@<https://hackage.haskell.org/package/stock-aeson stock-aeson>@__: @<https://hackage-content.haskell.org/package/aeson-2.3.0.0/docs/Data-Aeson.html#t:ToJSON ToJSON>@, @<https://hackage-content.haskell.org/package/aeson-2.3.0.0/docs/Data-Aeson.html#t:ToJSON1 ToJSON1>@, @<https://hackage-content.haskell.org/package/aeson-2.3.0.0/docs/Data-Aeson.html#t:ToJSON2 ToJSON2>@; @<https://hackage-content.haskell.org/package/aeson-2.3.0.0/docs/Data-Aeson.html#t:FromJSON FromJSON>@, @<https://hackage-content.haskell.org/package/aeson-2.3.0.0/docs/Data-Aeson.html#t:FromJSON1 FromJSON1>@, @<https://hackage-content.haskell.org/package/aeson-2.3.0.0/docs/Data-Aeson.html#t:FromJSON2 FromJSON2>@
  * __@<https://hackage.haskell.org/package/stock-quickcheck stock-quickcheck>@__: @<https://hackage-content.haskell.org/package/QuickCheck-2.18.0.0/docs/Test-QuickCheck.html#t:Arbitrary Arbitrary>@, @<https://hackage-content.haskell.org/package/QuickCheck-2.18.0.0/docs/Test-QuickCheck.html#t:Arbitrary1 Arbitrary1>@, @<https://hackage-content.haskell.org/package/QuickCheck-2.18.0.0/docs/Test-QuickCheck.html#t:Arbitrary2 Arbitrary2>@; @<https://hackage-content.haskell.org/package/QuickCheck-2.18.0.0/docs/Test-QuickCheck.html#t:CoArbitrary CoArbitrary>@
  * __@<https://hackage.haskell.org/package/stock-profunctors stock-profunctors>@__: @<https://hackage-content.haskell.org/package/profunctors-5.6.3/docs/Data-Profunctor.html#t:Profunctor Profunctor>@

  Ordinary @DerivingVia@ modifiers compose with
  <https://hackage-content.haskell.org/package/stock-0.1.0.2/docs/Stock.html#t:Stock Stock>:

  * @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Ord.html#t:Down Down (Stock T)>@ reverses ordering, enumeration and bounds
  * @<https://hackage-content.haskell.org/package/transformers-0.6.3.0/docs/Control-Applicative-Backwards.html#t:Backwards Backwards (Stock1 F)>@ reverses @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Control-Applicative.html#t:Applicative Applicative>@ effects
  * @<https://hackage-content.haskell.org/package/transformers-0.6.3.0/docs/Data-Functor-Reverse.html#t:Reverse Reverse (Stock1 F)>@ reverses @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Foldable.html#t:Foldable Foldable>@ \/ @<https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Data-Traversable.html#t:Traversable Traversable>@

  > {-# 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
                     negative/run-negative.sh

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

-- Override-via-newtype coverage: derive each class through a modifier newtype
-- (Sum / Down / Compose / Op / Basic / …) and assert the reshape took effect.
test-suite overrides
  import:           warnings
  type:             exitcode-stdio-1.0
  main-is:          Overrides.hs
  build-depends:    base >=4.18 && <5, stock
  ghc-options:      -fplugin=Stock
  hs-source-dirs:   test

-- Should-fail harness: compiles invalid per-field overrides and asserts the
-- plugin rejects them (with valid controls that must still compile).  Runs
-- negative/run-negative.sh (compile-must-fail can't live in a normal module).
test-suite negative
  import:           warnings
  type:             exitcode-stdio-1.0
  main-is:          RunNegative.hs
  build-depends:    base >=4.18 && <5,
                    process
  hs-source-dirs:   negative

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