@hackage / stock-quickcheck

Derive Arbitrary via the stock plugin

Latest0.1.0.0

About

Metadata

  • Last updated , by BaldurBlondal
  • License BSD-3-Clause
  • Categories Type System
  • Maintained by: baldur.blondal@iohk.io

  • Lottery factor: 0

Links

Installation

Tested Compilers

  1. 9.10.3
  2. 9.10.3
  3. 9.8.1

Readme

The stock plugin provides a newtype Stock for deriving and synthesising instances at compile time. stock-quickcheck extends it to support Arbitrary, CoArbitrary, and their higher-kinded variants.

{-# options_ghc -fplugin Stock #-}

{-# language DerivingVia #-}
{-# language DataKinds   #-}

import Stock
import Stock.QuickCheck

import Test.QuickCheck

data Person = P { name :: String, age :: Int }
  deriving (Eq, Ord, Show, Read) via
    Stock Person
  deriving Arbitrary via
    Overriding Person
      [ name via ASCIIString, age via Positive ]

stock-quickcheck provides four instances, that signal to the plugin how to derive Arbitrary, Arbitrary1, Arbitrary2 and CoArbitrary.

arbitrary is structural and size-aware, in the style of generic-arbitrary. It picks a constructor, preferring terminal constructors once the size runs out, so recursive types terminate, and fills each field with its own arbitrary, dividing the size among recursive fields. shrink defaults.

instance DeriveStock  Arbitrary   ..
instance DeriveStock1 Arbitrary1  ..
instance DeriveStock2 Arbitrary2  ..
instance DeriveStock  CoArbitrary ..

stock companion packages include: