Implement custom at and ix for NewInt types
This commit is contained in:
+10
-5
@@ -4,6 +4,8 @@
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
||||
{-# LANGUAGE DerivingStrategies #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
--{-# LANGUAGE StandaloneDeriving #-}
|
||||
module NewInt where
|
||||
|
||||
--import qualified Data.IntSet as IS
|
||||
@@ -19,11 +21,14 @@ newtype NewIntMap a b = NIntMap { _unNIntMap :: IM.IntMap b}
|
||||
deriving newtype (Monoid,Semigroup)
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
|
||||
--instance Ixed (NewIntMap (NewInt a)) where
|
||||
-- type Index (NewIntMap (NewInt a)) = NewInt a
|
||||
-- type Index (NewIntMap (NewInt a)) = NewInt a
|
||||
-- ix :: (NewInt a) -> IndexedTraversal' (NewIntMap (NewInt a))
|
||||
-- ix (NInt k) (NewIntMap m) = NIntMap <$> ix k m
|
||||
type instance Index (NewIntMap a b) = NewInt a
|
||||
type instance IxValue (NewIntMap a b) = b
|
||||
|
||||
instance Ixed (NewIntMap a b) where
|
||||
ix (NInt i) f (NIntMap m) = fmap NIntMap (ix i f m)
|
||||
|
||||
instance At (NewIntMap a b) where
|
||||
at (NInt i) f (NIntMap m) = fmap NIntMap (at i f m)
|
||||
|
||||
makeLenses ''NewInt
|
||||
makeLenses ''NewIntMap
|
||||
|
||||
Reference in New Issue
Block a user