feat: Read and Show for all the types

This commit is contained in:
vegowotenks 2025-08-12 14:22:59 +02:00
parent bf525c2dfd
commit fd715d99e0
9 changed files with 87 additions and 25 deletions

View file

@ -1,17 +1,25 @@
{-# LANGUAGE Safe #-}
{-# LANGUAGE TypeFamilies #-}
--
{-# LANGUAGE StandaloneDeriving #-} -- specify instance contexts
{-# LANGUAGE FlexibleContexts #-} -- use non type-variable argument in instance head
{-# LANGUAGE UndecidableInstances #-} -- use type family in instance head
-- | A Map that derives the keys for the mapping from the items.
module Data.Map.Implicit (ImplicitMap(), get, ImplicitKeyOf(..), empty) where
import Data.Kind (Type, Constraint)
import Data.Map (Map)
import Data.Map qualified as Map
import Text.Show (Show)
import Text.Read (Read)
import Data.Ord (Ord)
type ImplicitMap :: Type -> Type
type role ImplicitMap nominal
newtype ImplicitMap v = ImplicitMap { get :: Map (KeyType v) v }
deriving stock instance (Show (KeyType v), Show v) => Show (ImplicitMap v)
deriving stock instance (Read (KeyType v), Ord (KeyType v), Read v) => Read (ImplicitMap v)
type ImplicitKeyOf :: Type -> Constraint
class ImplicitKeyOf v where