Add generic derivations and To/FromJSON instances

This commit is contained in:
2022-07-25 22:49:18 +01:00
parent f5604ef429
commit b8e8413daa
99 changed files with 1406 additions and 517 deletions
+39 -1
View File
@@ -1,6 +1,14 @@
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE DeriveGeneric #-}
{-# OPTIONS_GHC -Wno-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{- |
WARNING: orphan instances concerning Aeson classes and Data.Strict.IntMap datatypes have been introduced.
The warnings have been disabled.
-}
module IntMapHelp
( module Data.Strict.IntMap
--( module Data.IntMap.Strict
, newKey
, insertNewKey
, insertWithNewKeys
@@ -8,10 +16,40 @@ module IntMapHelp
, safeSwapKeys
, findIndex
) where
import GHC.Generics
import Data.Aeson
import LensHelp
--import Data.List hiding (foldr,insert)
--import Data.IntMap.Strict
import Data.Strict.IntMap
import Data.Strict.Containers.Lens
--import qualified Data.Strict.IntMap as IM
--import qualified Data.Strict.IntMap.Autogen.Strict as IM
--deriving instance Generic (IntMap a)
--deriving instance (Generic a) => Generic (IM.IntMap a)
instance ToJSON1 IntMap where
liftToJSON t tol = liftToJSON to' tol' . toList
where
to' = liftToJSON2 toJSON toJSONList t tol
tol' = liftToJSONList2 toJSON toJSONList t tol
liftToEncoding t tol = liftToEncoding to' tol' . toList
where
to' = liftToEncoding2 toEncoding toEncodingList t tol
tol' = liftToEncodingList2 toEncoding toEncodingList t tol
instance ToJSON a => ToJSON (IntMap a) where
toJSON = toJSON1
toEncoding = toEncoding1
instance FromJSON a => FromJSON (IntMap a) where
parseJSON = fmap fromList . parseJSON
--instance ToJSON a => ToJSON (IntMap a) where
-- toEncoding = genericToEncoding defaultOptions
{- | Find a key value one higher than any key in the map, or zero if the map is
- empty -}
newKey :: IntMap a -> Int