Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dhall: provide *WithIndex instances for Map #2633

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions dhall/src/Dhall/Map.hs
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading