Skip to content

Commit

Permalink
Merge pull request #1 from bruderj15/instances
Browse files Browse the repository at this point in the history
Instance Show for Somes
  • Loading branch information
bruderj15 authored Nov 29, 2024
2 parents 46074c8 + 2c932fa commit d6a9afd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
2 changes: 1 addition & 1 deletion constrained-some.cabal
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
14 changes: 12 additions & 2 deletions src/Data/Some/Constraint.hs
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)

0 comments on commit d6a9afd

Please sign in to comment.