{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} module Language.Symantic.Type.Map where import Data.Map.Strict as Map import Data.Maybe (isJust) import Data.Type.Equality ((:~:)(Refl)) import Language.Symantic.Type.Common -- * Type 'Type_Map' -- | The 'Map' type. data Type_Map root h where Type_Map :: Ord h_k => root h_k -> root h_a -> Type_Map root (Map h_k h_a) type instance Root_of_Type (Type_Map root) = root type instance Error_of_Type ast (Type_Map root) = No_Error_Type instance -- Type_Eq Type_Eq root => Type_Eq (Type_Map root) where type_eq (Type_Map k1 a1) (Type_Map k2 a2) | Just Refl <- k1 `type_eq` k2 , Just Refl <- a1 `type_eq` a2 = Just Refl type_eq _ _ = Nothing instance -- Eq Type_Eq root => Eq (Type_Map root h) where x == y = isJust $ type_eq x y instance -- String_from_Type String_from_Type root => String_from_Type (Type_Map root) where string_from_type (Type_Map k a) = "Map (" ++ string_from_type k ++ ")" ++ " (" ++ string_from_type a ++ ")" instance -- Show String_from_Type root => Show (Type_Map root h) where show = string_from_type -- | Convenient alias to include a 'Type_Map' within a type. type_map :: (Type_Root_Lift Type_Map root, Ord h_k) => root h_k -> root h_a -> root (Map h_k h_a) type_map k a = type_root_lift (Type_Map k a)