diff --git a/CHANGELOG.md b/CHANGELOG.md index e35e306..cb49b2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,12 @@ file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [PVP versioning](https://pvp.haskell.org/). -## Initial release: v0.0.1 _(2024-11-27)_ +## v0.1.1 _(2024-11-29)_ + +### Added +- Added instance `Show (Somes cs)` if `cs` contains `Show` + +## Initial release: v0.1.0 _(2024-11-27)_ ### Added - Existentials `Somes` and `Somes1` diff --git a/constrained-some.cabal b/constrained-some.cabal index 08698ec..7b5e938 100644 --- a/constrained-some.cabal +++ b/constrained-some.cabal @@ -1,6 +1,6 @@ cabal-version: 3.0 name: constrained-some -version: 0.1.0.0 +version: 0.1.1 synopsis: Existential type that can be constrained description: This library provides utilities for working with existential types and type-level constraints. It allows you to enforce multiple constraints on polymorphic types and containers complementing the package some. diff --git a/src/Data/Some/Constraint.hs b/src/Data/Some/Constraint.hs index 284ecd7..c709e58 100644 --- a/src/Data/Some/Constraint.hs +++ b/src/Data/Some/Constraint.hs @@ -1,10 +1,14 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE QuantifiedConstraints #-} {-# LANGUAGE StandaloneKindSignatures #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE GADTs #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE UndecidableInstances #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE ScopedTypeVariables #-} module Data.Some.Constraint where @@ -51,4 +55,10 @@ data Somes1 csf csa where (AllC csf f, AllC csa a) => f a -> Somes1 csf csa -- | Alias for 'Somes1' with just one 'Constraint'. -type Some1 ca cf = Somes1 '[ca] '[cf] +type Some1 cf ca = Somes1 '[cf] '[ca] + +instance {-# OVERLAPPING #-} Show (Somes (Show ': cs)) where + showsPrec d (Some x) = showParen (d > 10) $ showString "Some " . showsPrec 11 x + +instance {-# OVERLAPPABLE #-} Show (Somes cs) => Show (Somes (c ': cs)) where + showsPrec d (Some x) = showsPrec d (Some @cs x)