1{-# LANGUAGE TemplateHaskell #-}
4-- Module : Streamly.Test.Data.Serialize.TH
5-- Copyright : (c) 2022 Composewell technologies
6-- License : BSD-3-Clause
7-- Maintainer : streamly@composewell.com
8-- Stability : experimental
11module Streamly.Test.Data.Serialize.TH (genDatatype) where
13--------------------------------------------------------------------------------
15--------------------------------------------------------------------------------
17import Language.Haskell.TH
19import Test.QuickCheck.Arbitrary (Arbitrary(..))
20import Test.QuickCheck.Gen (oneof)
22--------------------------------------------------------------------------------
24--------------------------------------------------------------------------------
26genDatatype :: String -> Int -> Q [Dec]
27genDatatype tyName numCons =
34 (mkCon <$> [0 .. (numCons - 1)])
35 [derivClause Nothing [conT ''Eq, conT ''Show]]
38 (appT (conT ''Arbitrary) (conT (mkName tyName)))
48 [0 .. (numCons - 1)]))))
60 , appT listT (conT ''Int)
61 , appT listT (conT ''String)
62 , appT listT (appT listT (conT ''Int))
63 , appT listT (appT listT (conT ''String))
66 chooseCycle i xs = xs !! (i `mod` length xs)
70 (\b a -> [|$(b) <*> $(a)|])
71 [|pure $(conE (mkName ("Constructor" ++ show i)))|]
72 (replicate i (varE 'arbitrary))
76 (mkName ("Constructor" ++ show i))
77 (mkField <$> [0..(i - 1)])
81 (bang noSourceUnpackedness noSourceStrictness)
82 (chooseCycle i fieldTypeChoices)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list