store-0.7.18: Fast binary serialization
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Store.TH

Description

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

makeStore can be used to generate a Store instance for types, when all the type variables also require Store instances. If some do not, then instead use TH.Derive like this:

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ScopedTypeVariables #-}

import TH.Derive
import Data.Store

data Foo a = Foo a | Bar Int

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

Note that when used with datatypes that require type variables, the ScopedTypeVariables extension is required.

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

Documentation

makeStore :: Name -> Q [Dec] Source #

Given the name of a type, generate a Store instance for it, assuming that all type variables also need to be Store instances.

Note that when used with datatypes that require type variables, the ScopedTypeVariables extension is required.

Testing Store instances

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

Test a Store instance using smallcheck and hspec.

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

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

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