1{-# LANGUAGE TemplateHaskell #-}
3module Streamly.Benchmark.Data.Serialize.TH (genLargeRecord) where
5--------------------------------------------------------------------------------
7--------------------------------------------------------------------------------
9import Language.Haskell.TH
11import Streamly.Internal.Data.Serialize.TH.Bottom (makeI)
12import Control.DeepSeq (NFData(..))
14--------------------------------------------------------------------------------
16--------------------------------------------------------------------------------
18genLargeRecord :: String -> Int -> Q [Dec]
19genLargeRecord tyName numFields =
27 [derivClause Nothing [conT ''Eq, conT ''Show]]
30 , nfDataInstance tyName
35 fieldTypeChoices = [conT ''()]
36 chooseCycle i xs = xs !! (i `mod` length xs)
40 (appT (conT ''NFData) (conT (mkName nm)))
46 (varP . makeI <$> [0 .. (numFields - 1)])
50 (\b a -> [|rnf $(b) `seq` rnf $(a)|])
52 (varE . makeI <$> [0 .. (numFields - 1)])))
56 valueName = mkName $ "val" ++ tyName
57 mkValueSigDec = sigD valueName [t|$(conT (mkName tyName))|]
65 (\b a -> [|$(b) $(a)|])
66 (conE (mkName tyName))
67 (const (conE '()) <$> [0 .. (numFields - 1)])))
70 mkCon nm = recC (mkName nm) (mkField <$> [0 .. (numFields - 1)])
73 (mkName ("field" ++ show i))
75 (bang noSourceUnpackedness noSourceStrictness)
76 (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