diff --git a/cardano-base/CHANGELOG.md b/cardano-base/CHANGELOG.md index 5babaca4c..ec9083503 100644 --- a/cardano-base/CHANGELOG.md +++ b/cardano-base/CHANGELOG.md @@ -2,6 +2,7 @@ ## 0.1.4.0 +* Add `Cardano.Base.Typeable` module with type `TypeName a` and its `IsString` and `Show` instances. * Add a workaround for QuickCheck >= 2.18 replacing `withMaxSuccess` with `withNumTests` and deprecating the former. diff --git a/cardano-base/cardano-base.cabal b/cardano-base/cardano-base.cabal index 4dcbed4f3..ab6447d29 100644 --- a/cardano-base/cardano-base.cabal +++ b/cardano-base/cardano-base.cabal @@ -44,6 +44,7 @@ library Cardano.Base.FeatureFlags Cardano.Base.IP Cardano.Base.Proxy + Cardano.Base.Typeable build-depends: aeson, diff --git a/cardano-base/src/Cardano/Base/Typeable.hs b/cardano-base/src/Cardano/Base/Typeable.hs new file mode 100644 index 000000000..62a87fb37 --- /dev/null +++ b/cardano-base/src/Cardano/Base/Typeable.hs @@ -0,0 +1,23 @@ +{-# LANGUAGE GADTs #-} +{-# LANGUAGE LambdaCase #-} + +-- | Wrapper for Data.Typeable, plus convenience functions +module Cardano.Base.Typeable ( + module X, + TypeName (..), +) where + +import Data.String (IsString (fromString)) +import Data.Typeable as X + +data TypeName a where + TypeNameString :: String -> TypeName a + TypeName :: Typeable a => TypeName a + +instance IsString (TypeName a) where + fromString = TypeNameString + +instance Show (TypeName a) where + show = \case + TypeNameString name -> name + t@(TypeName {}) -> show (typeRep t)