Skip to content

Commit

Permalink
Derive some instances earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
facundominguez authored and mgsloan committed Aug 16, 2021
1 parent a02bd78 commit c825313
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Data/Store/Internal.hs
Expand Up @@ -85,6 +85,7 @@ import Data.Functor.Identity (Identity (..))
import Data.HashMap.Strict (HashMap)
import Data.HashSet (HashSet)
import Data.Hashable (Hashable)
import Data.Int
import Data.IntMap (IntMap)
import qualified Data.IntMap.Strict as IntMap
import Data.IntSet (IntSet)
Expand Down Expand Up @@ -158,6 +159,16 @@ import GHC.Prim (sizeofByteArray#)
#endif
#endif

-- TODO: higher arities? Limited now by Generics instances for tuples
$(return $ map deriveTupleStoreInstance [2..7])

$(deriveManyStoreFromStorable
(\ty ->
case ty of
ConT n | elem n [''Char, ''Int, ''Int64, ''Word, ''Word8, ''Word32] -> True
_ -> False
))

------------------------------------------------------------------------
-- Utilities for defining list-like 'Store' instances in terms of 'IsSequence'

Expand Down Expand Up @@ -726,6 +737,8 @@ instance Store a => Store (Ratio a) where
-- Similarly, manual implementation due to no Generic instance for
-- Complex and Identity in GHC-7.10 and earlier.

$($(derive [d| instance Deriving (Store (Fixed a)) |]))

instance Store Time.DiffTime where
size = contramap (realToFrac :: Time.DiffTime -> Pico) size
poke = poke . (realToFrac :: Time.DiffTime -> Pico)
Expand Down Expand Up @@ -758,8 +771,6 @@ $($(derive [d|
instance Deriving (Store Bool)
instance (Store a, Store b) => Deriving (Store (Either a b))

instance Deriving (Store (Fixed a))

instance Deriving (Store Time.AbsoluteTime)
instance Deriving (Store Time.Day)
instance Deriving (Store Time.LocalTime)
Expand Down Expand Up @@ -789,8 +800,7 @@ $($(derive [d|

|]))

-- TODO: higher arities? Limited now by Generics instances for tuples
$(return $ map deriveTupleStoreInstance [2..7])
$(deriveManyStorePrimVector)

$(deriveManyStoreUnboxVector)

Expand All @@ -817,8 +827,6 @@ $(deriveManyStoreFromStorable
_ -> True
))

$(deriveManyStorePrimVector)

$(reifyManyWithoutInstances ''Store [''ModName, ''NameSpace, ''PkgName] (const True) >>=
mapM (\name -> return (deriveGenericInstance [] (ConT name))))

Expand Down

0 comments on commit c825313

Please sign in to comment.