packages feed

coercible-subtypes 0.1.0.0 → 0.1.1.0

raw patch · 4 files changed

+55/−18 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Data.Type.Coercion.Sub: arrR :: Sub a a' -> Sub b b' -> Sub (a' -> b) (a -> b')
+ Data.Type.Coercion.Sub: infixr 1 `arrR`
+ Data.Type.Coercion.Sub: infixr 2 `sumR`
+ Data.Type.Coercion.Sub: infixr 3 `prodR`
+ Data.Type.Coercion.Sub: instantiate :: forall j k (f :: j -> k) (g :: j -> k) (a :: j). Sub f g -> Sub (f a) (g a)
+ Data.Type.Coercion.Sub: prod3R :: Sub a a' -> Sub b b' -> Sub c c' -> Sub (a, b, c) (a', b', c')
+ Data.Type.Coercion.Sub: prodR :: Sub a a' -> Sub b b' -> Sub (a, b) (a', b')
+ Data.Type.Coercion.Sub: sumR :: Sub a a' -> Sub b b' -> Sub (Either a b) (Either a' b')
+ Data.Type.Coercion.Sub.Internal: instance forall k (a :: k) (b :: k). GHC.Types.Coercible a b => GHC.Enum.Bounded (Data.Type.Coercion.Sub.Internal.Sub a b)
+ Data.Type.Coercion.Sub.Internal: instance forall k (a :: k) (b :: k). GHC.Types.Coercible a b => GHC.Enum.Enum (Data.Type.Coercion.Sub.Internal.Sub a b)
+ Data.Type.Coercion.Sub.Internal: instance forall k (a :: k) (b :: k). GHC.Types.Coercible a b => GHC.Read.Read (Data.Type.Coercion.Sub.Internal.Sub a b)
- Data.Type.Coercion.Sub.Internal: Sub :: Coercion a b -> Sub
+ Data.Type.Coercion.Sub.Internal: Sub :: Coercion a b -> Sub (a :: k) (b :: k)
- Data.Type.Coercion.Sub.Internal: [getSub] :: Sub -> Coercion a b
+ Data.Type.Coercion.Sub.Internal: [getSub] :: Sub (a :: k) (b :: k) -> Coercion a b

Files

CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for coercible-subtypes +## 0.1.1.0 -- 2021-08-24++* Add instances `Coercible a b => (Read (Sub a b), Enum (Sub a b), Bounded (Sub a b))`+* Add `instantiate`+* Add some more combinators+ ## 0.1.0.0 -- 2020-04-08  * First version.
coercible-subtypes.cabal view
@@ -1,6 +1,6 @@ cabal-version:       2.2 name:                coercible-subtypes-version:             0.1.0.0+version:             0.1.1.0 stability:           experimental synopsis:            Coercible but only in one direction description: Newtype wrapper 'Data.Type.Coercion.Sub.Sub'@@ -15,7 +15,7 @@ license-file:        LICENSE author:              Koji Miyazato maintainer:          viercc@gmail.com-copyright:           (c) 2020 Koji Miyazato+copyright:           (c) 2020-2021 Koji Miyazato category:            Data build-type:          Simple extra-source-files:  CHANGELOG.md, README.md@@ -28,7 +28,7 @@ library   exposed-modules:     Data.Type.Coercion.Sub,                        Data.Type.Coercion.Sub.Internal-  build-depends:       base >=4.12 && <4.15,+  build-depends:       base >=4.12 && <4.17,                        profunctors   hs-source-dirs:      src   default-language:    Haskell2010
src/Data/Type/Coercion/Sub.hs view
@@ -39,8 +39,9 @@    coercionIsSub, +  instantiate,   mapR, contramapR,-  bimapR, dimapR+  bimapR, prodR, prod3R, sumR, dimapR, arrR ) where  import           Data.Coerce@@ -96,26 +97,57 @@  ----------------------------- +-- | For a @Sub@ relation between type constructors @f@ and @g@,+--   create an instance of subtype relation @Sub (f a) (g a)@ for any type+--   parameter @a@.+instantiate :: forall j k (f :: j -> k) (g :: j -> k) (a :: j).+  Sub f g -> Sub (f a) (g a)+instantiate (Sub Coercion) = sub+ -- | Extend subtype relation covariantly. mapR :: ( forall x x'. Coercible x x' => Coercible (t x) (t x')         , Functor t)      => Sub a b -> Sub (t a) (t b) mapR (Sub Coercion) = Sub Coercion --- | Extend subtype relation contravariantly+-- | Extend subtype relation contravariantly. contramapR :: ( forall x x'. Coercible x x' => Coercible (t x) (t x')               , Contravariant t)            => Sub a b -> Sub (t b) (t a) contramapR (Sub Coercion) = Sub Coercion +-- | Extend subtype relation over a 'Bifunctor'. bimapR :: ( forall x x' y y'.               (Coercible x x', Coercible y y') => Coercible (t x y) (t x' y')           , Bifunctor t)        => Sub a a' -> Sub b b' -> Sub (t a b) (t a' b') bimapR (Sub Coercion) (Sub Coercion) = Sub Coercion +-- | 'bimapR' specialized for the pair type '(a,b)'+prodR :: Sub a a' -> Sub b b' -> Sub (a,b) (a',b')+prodR = bimapR++infixr 3 `prodR`++-- | 'bimapR' specialized for 'Either'+sumR :: Sub a a' -> Sub b b' -> Sub (Either a b) (Either a' b')+sumR = bimapR++infixr 2 `sumR`++-- | Extend subtype relation over the 3-tuple types '(a,b,c)'+prod3R :: Sub a a' -> Sub b b' -> Sub c c' -> Sub (a,b,c) (a',b',c')+prod3R (Sub Coercion) (Sub Coercion) (Sub Coercion) = Sub Coercion++-- | Extend subtype relation over a 'Profunctor'. dimapR :: ( forall x x' y y'.               (Coercible x x', Coercible y y') => Coercible (t x y) (t x' y')           , Profunctor t)        => Sub a a' -> Sub b b' -> Sub (t a' b) (t a b') dimapR (Sub Coercion) (Sub Coercion) = Sub Coercion++-- | 'dimapR' specialized for '(->)'+arrR :: Sub a a' -> Sub b b' -> Sub (a' -> b) (a -> b')+arrR = dimapR++infixr 1 `arrR`
src/Data/Type/Coercion/Sub/Internal.hs view
@@ -1,7 +1,9 @@ {-# LANGUAGE GADTs                 #-} {-# LANGUAGE InstanceSigs          #-} {-# LANGUAGE PolyKinds             #-}-+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE DerivingStrategies #-}+{-# LANGUAGE StandaloneDeriving #-} {- |  This module exposes internals of "Data.Type.Coercion.Sub".@@ -18,21 +20,18 @@ import           Control.Category import           Prelude                    hiding (id, (.)) +import           Data.Coerce import           Data.Type.Coercion  newtype Sub (a :: k) (b :: k) = Sub { getSub :: Coercion a b }-  deriving (Eq, Ord, Show)--- It is intentional to omit some instances.------ TestCoercion instance should not exist.--- Knowing `Sub a b` and `Sub a c` should not conclude--- `Coercible b c`.------ Among instances `Coercion` has, Enum, Bounded, and Read are--- excluded because they allows to make new value of `Sub a b`.--- Constructing `Sub a b` values must be done through--- combinators provided by this module or exported for--- abstract type under library author's careful choice.+  deriving stock (Eq, Ord, Show)+-- It is intentional to omit the 'TestCoercion' instance, existing for @Coercion@.+-- Knowing @Sub a b@ and @Sub a c@ should not conclude+-- @Coercible b c@.++deriving stock instance Coercible a b => Read (Sub a b)+deriving newtype instance Coercible a b => Enum (Sub a b)+deriving newtype instance Coercible a b => Bounded (Sub a b)  instance Category Sub where   id :: Sub a a