Data.Store.TH

store-0.4.2: Fast binary serialization

Safe Haskell | None
Language | Haskell2010

Data.Store.TH

Contents

- Testing Store instances

Description

This module exports TH utilities intended to be useful to users.

However, the visible exports do not show the main things that will be useful, which is using TH to generate `Store` instances, via TH.Derive. It's used like this:

        data Foo = Foo Int | Bar Int

        $($(derive [d|
            instance Deriving (Store Foo)
            |]))

One advantage of using this Template Haskell definition of Store instances is that in some cases they can be faster than the instances defined via Generics. Specifically, sum types which can yield `ConstSize` from `size` will be faster when used in array-like types. The instances generated via generics always use `VarSize` for sum types.

Synopsis

- smallcheckManyStore :: Bool -> Int -> [TypeQ] -> ExpQ
- checkRoundtrip :: (Eq a, Show a, Store a) => Bool -> a -> Bool
- assertRoundtrip :: (Eq a, Show a, Store a, Monad m, Typeable a) => Bool -> a -> m ()

# Testing Store instances

smallcheckManyStore :: Bool -> Int -> [TypeQ] -> ExpQ #

Test a `Store` instance using `smallcheck` and `hspec`.

checkRoundtrip :: (Eq a, Show a, Store a) => Bool -> a -> Bool #

Check if a given value succeeds in decoding its encoded representation.

assertRoundtrip :: (Eq a, Show a, Store a, Monad m, Typeable a) => Bool -> a -> m () #