From 1745ffc66863078e6f0e99abd08f002f7f31f695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berk=20=C3=96zk=C3=BCt=C3=BCk?= Date: Mon, 20 Jan 2025 23:19:59 +0100 Subject: [PATCH] dhall: provide `*WithIndex` instances for `Map` --- dhall/src/Dhall/Map.hs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/dhall/src/Dhall/Map.hs b/dhall/src/Dhall/Map.hs index d696fad33..5fc8e0dc7 100644 --- a/dhall/src/Dhall/Map.hs +++ b/dhall/src/Dhall/Map.hs @@ -1,9 +1,11 @@ -{-# LANGUAGE DeriveAnyClass #-} -{-# LANGUAGE DeriveDataTypeable #-} -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE DeriveLift #-} -{-# LANGUAGE ExplicitForAll #-} -{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DeriveLift #-} +{-# LANGUAGE ExplicitForAll #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE TypeFamilies #-} -- | `Map` type used to represent records and unions @@ -76,9 +78,12 @@ import Instances.TH.Lift () import Language.Haskell.TH.Syntax (Lift) import Prelude hiding (filter, lookup) +import qualified Data.Foldable.WithIndex as Foldable.WithIndex +import qualified Data.Functor.WithIndex as Functor.WithIndex import qualified Data.List import qualified Data.Map.Strict import qualified Data.Set +import qualified Data.Traversable.WithIndex as Traversable.WithIndex import qualified GHC.Exts import qualified Prelude @@ -158,6 +163,18 @@ instance Ord k => GHC.Exts.IsList (Map k v) where toList = Dhall.Map.toList +instance Ord k => Foldable.WithIndex.FoldableWithIndex k (Map k) where + ifoldMap = foldMapWithKey + {-# INLINABLE ifoldMap #-} + +instance Functor.WithIndex.FunctorWithIndex k (Map k) where + imap = mapWithKey + {-# INLINABLE imap #-} + +instance Ord k => Traversable.WithIndex.TraversableWithIndex k (Map k) where + itraverse = traverseWithKey + {-# INLINABLE itraverse #-} + -- | Create an empty `Map` empty :: Ord k => Map k v empty = mempty