summaryrefslogtreecommitdiff
path: root/src/Data
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data')
-rw-r--r--src/Data/Dependent/EnumMap/Strict/Internal.hs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/Data/Dependent/EnumMap/Strict/Internal.hs b/src/Data/Dependent/EnumMap/Strict/Internal.hs
index 17de2fd..1a26f1a 100644
--- a/src/Data/Dependent/EnumMap/Strict/Internal.hs
+++ b/src/Data/Dependent/EnumMap/Strict/Internal.hs
@@ -1,6 +1,7 @@
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Dependent.EnumMap.Strict.Internal where
@@ -8,7 +9,9 @@ module Data.Dependent.EnumMap.Strict.Internal where
import Data.Bifunctor (bimap)
import Data.Dependent.Sum
import qualified Data.IntMap.Strict as IM
+import Data.Kind (Type)
import Data.Some
+import Text.Show (showListWith)
import Unsafe.Coerce (unsafeCoerce)
@@ -16,6 +19,11 @@ data KV k v = forall a. KV !(Enum1Info k) !(v a)
newtype DEnumMap k v = DEnumMap (IM.IntMap (KV k v))
+instance (Enum1 k, forall a. Show (k a), forall a. Show (v a))
+ => Show (DEnumMap (k :: kind -> Type) (v :: kind -> Type)) where
+ showsPrec d mp = showParen (d > 10) $
+ showString "DEnumMap " . showListWith (\(k :=> v) -> showsPrec 2 k . showString " :=> " . showsPrec 1 v) (toList mp)
+
class Enum1 f where
type Enum1Info f
fromEnum1 :: f a -> (Int, Enum1Info f)
@@ -213,11 +221,15 @@ keys (DEnumMap m) = map (\(k, KV inf _) -> toEnum1 k inf) (IM.assocs m)
-- ** Lists
--- toList
+toList :: Enum1 k => DEnumMap k v -> [DSum k v]
+toList = toAscList
-- ** Ordered lists
--- toAscList
+toAscList :: Enum1 k => DEnumMap k v -> [DSum k v]
+toAscList (DEnumMap m) =
+ map (\(i, KV inf v) -> case toEnum1 i inf of Some k -> k :=> coe1 v)
+ (IM.toAscList m)
toDescList :: Enum1 k => DEnumMap k v -> [DSum k v]
toDescList (DEnumMap m) =