packages feed

natural-transformation 0.3.1 → 0.4.1

raw patch · 8 files changed

Files

CHANGELOG.md view
@@ -1,3 +1,13 @@+# 0.4.1 [2024.10.27]+* Drop support for pre-8.0 versions of GHC.++# 0.4+* Rename `Nat` constructor to `NT`+* Rename `run` to `unwrapNT`+* Rename `nat` to `wrapNT`+* Backport the `Semigroup` instance for `(:~>)` by conditionally depending on+  the `semigroups` package+ # 0.3.1 * Adding `run` and `nat`. 
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2015, The University of Kansas+Copyright (c) 2015-2016, The University of Kansas  All rights reserved. 
README.md view
@@ -1,5 +1,5 @@-# natural-transformation [![Hackage version](https://img.shields.io/hackage/v/natural-transformation.svg?style=flat)](http://hackage.haskell.org/package/natural-transformation) [![Build Status](https://img.shields.io/travis/ku-fpg/natural-transformation.svg?style=flat)](https://travis-ci.org/ku-fpg/natural-transformation)+# natural-transformation [![Hackage version](https://img.shields.io/hackage/v/natural-transformation.svg?style=flat)](http://hackage.haskell.org/package/natural-transformation) [![Build Status](https://github.com/ku-fpg/natural-transformation/workflows/Haskell-CI/badge.svg)](https://github.com/ku-fpg/natural-transformation/actions?query=workflow%3AHaskell-CI) -A natural transformation transforms a container `f a` into another container `g a`. -Natural transformations act as functor morphisms in category theory. +A natural transformation transforms a container `f a` into another container `g a`.+Natural transformations act as functor morphisms in category theory. Technically, `f` and `g` should be functors, but we allow any correctly-shaped structure.
natural-transformation.cabal view
@@ -1,5 +1,5 @@ name:                natural-transformation-version:             0.3.1+version:             0.4.1 synopsis:            A natural transformation package. description:         A natural transformation transforms a container @f a@ into another                      container @g a@. Natural transformations act as functor morphisms@@ -14,23 +14,34 @@ stability:           Provisional author:              Andy Gill maintainer:          Andy Gill <andygill@ku.edu>-copyright:           Copyright (c) 2015 The University of Kansas+copyright:           Copyright (c) 2015-2016 The University of Kansas category:            Control build-type:          Simple extra-source-files:  CHANGELOG.md, README.md-tested-with:         GHC == 7.8.4, GHC == 7.10.3+tested-with:         GHC == 8.0.2+                   , GHC == 8.2.2+                   , GHC == 8.4.4+                   , GHC == 8.6.5+                   , GHC == 8.8.4+                   , GHC == 8.10.7+                   , GHC == 9.0.2+                   , GHC == 9.2.8+                   , GHC == 9.4.8+                   , GHC == 9.6.6+                   , GHC == 9.8.2+                   , GHC == 9.10.1 cabal-version:       >= 1.10  source-repository head   type:                git-  location:            git://github.com/ku-fpg/natural-transformation+  location:            https://github.com/ku-fpg/natural-transformation  library   exposed-modules:     Control.Natural                        Control.Natural.RULES                        Control.Object-                       -  build-depends:       base >= 4.7 && < 5++  build-depends:       base       >= 4.9  && < 5   hs-source-dirs:      src   default-language:    Haskell2010   ghc-options:         -Wall@@ -38,12 +49,12 @@ test-suite natural-transformation-properties   type:                exitcode-stdio-1.0   main-is:             Properties.hs-  build-depends:       base                   >= 4.7 && < 5-                     , containers             >= 0.1 && < 0.6-                     , natural-transformation == 0.3.1+  build-depends:       base                   >= 4.9 && < 5+                     , containers             >= 0.1 && < 0.8+                     , natural-transformation                      , quickcheck-instances   >= 0.1 && < 0.4-                     , tasty                  >= 0.8 && < 0.12-                     , tasty-quickcheck       >= 0.8 && < 0.9+                     , tasty                  >= 0.8 && < 1.6+                     , tasty-quickcheck       >= 0.8 && < 0.11   hs-source-dirs:      tests   default-language:    Haskell2010   ghc-options:         -Wall
src/Control/Natural.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE CPP #-}-{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE GADTs #-}@@ -24,21 +23,17 @@     -- * Type Synonym for a Natural Transformation   , type (~>)     -- * Conversion functions between the newtype and the synonym-  , run-  , nat+  , wrapNT+  , unwrapNT     -- * Class for Natural Transformations   , Transformation(..)   ) where  import qualified Control.Category as C (Category(..)) -#if !(MIN_VERSION_base(4,8,0))-import           Data.Monoid (Monoid(..))-#endif-#if MIN_VERSION_base(4,9,0)+#if !(MIN_VERSION_base(4,11,0)) import           Data.Semigroup (Semigroup(..)) #endif-import           Data.Typeable  --------------------------------------------------------------------------- -- Naming of ~>, :~> and $$ are taken (with permission) from Edward Kmett's @indexed@ package.@@ -50,21 +45,18 @@  infixr 0 :~>, $$ -- | A natural transformation suitable for storing in a container.-newtype f :~> g = Nat { ($$) :: f ~> g }-  deriving Typeable+newtype f :~> g = NT { ($$) :: f ~> g }  instance C.Category (:~>) where-    id = Nat id-    Nat f . Nat g = Nat (f . g)+    id = NT id+    NT f . NT g = NT (f . g) -#if MIN_VERSION_base(4,9,0) instance f ~ g => Semigroup (f :~> g) where-    Nat f <> Nat g = Nat (f . g)-#endif+    NT f <> NT g = NT (f . g)  instance f ~ g => Monoid (f :~> g) where-    mempty = Nat id-    mappend (Nat f) (Nat g) = Nat (f . g)+    mempty = NT id+    mappend = (<>)  infix 0 # -- | A (natural) transformation is inside @t@, and contains @f@ and @g@@@ -78,14 +70,17 @@     (#) :: t -> forall a . f a -> g a  instance Transformation f g (f :~> g) where-    Nat f # g = f g+    NT f # g = f g --- | 'run' is the nonfix version of @#@. It is used to break natural---   transformation wrappers, including ':~>'.-run :: Transformation f g t => t -> (forall a . f a -> g a)-run = (#)+-- | 'wrapNT' builds our natural transformation abstraction out of+-- a natural transformation function.+--+-- An alias to 'NT' provided for symmetry with 'unwrapNT'.+--+wrapNT :: (forall a . f a -> g a) -> f :~> g+wrapNT = NT --- | 'nat' builds our natural transformation abstraction out of---    a natural transformation function.-nat :: (forall a . f a -> g a) -> f :~> g-nat = Nat+-- | 'unwrapNT' is the nonfix version of @#@. It is used to break natural+--   transformation wrappers, including ':~>'.+unwrapNT :: Transformation f g t => t -> (forall a . f a -> g a)+unwrapNT = (#)
src/Control/Natural/RULES.hs view
@@ -2,7 +2,7 @@ {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE Trustworthy #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# OPTIONS_GHC -Wno-orphans #-}  {-| Module:      Control.Transformation.RULES
src/Control/Object.hs view
@@ -22,4 +22,4 @@ newtype Object f = Object (f ~> IO)  instance Transformation f IO (Object f) where-    Object f # g = Nat f # g+    Object f # g = NT f # g
tests/Properties.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE TypeOperators #-} {-| Module:      Main@@ -14,9 +13,6 @@ import Control.Natural  import Data.Foldable (toList)-#if !(MIN_VERSION_base(4,8,0))-import Data.Monoid (Monoid(..))-#endif import Data.Sequence (Seq, fromList)  import Test.QuickCheck.Instances ()@@ -34,7 +30,7 @@     ]  -- | Verifies the free theorem for natural transformations, i.e., that--- +-- -- @ -- fmap h . r == r . fmap h -- @@@ -43,7 +39,7 @@ prop_freeTheorem h r t = fmap h (r # t) == (r # fmap h t)  -- | Verifies that natural transformations form a law-abiding 'Monoid', i.e., that--- +-- --  * @mappend mempty x = x@ -- --  * @mappend x mempty = x@@@ -58,19 +54,19 @@  -- | A natural transformations from lists to lists that 'reverse's. listReverseNT :: [] :~> []-listReverseNT = Nat reverse+listReverseNT = NT reverse  -- | A natural transformation from lists to lists that shifts all elements to the left, -- moving the head element to the back. listShiftNT :: [] :~> []-listShiftNT = Nat $ \l -> case l of+listShiftNT = NT $ \l -> case l of                                []     -> []                                (x:xs) -> xs ++ [x]  -- | A natural transformation from lists to 'Seq's. listSeqNT :: [] :~> Seq-listSeqNT = Nat fromList+listSeqNT = NT fromList  -- | A natural transformation from 'Seq's to lists. seqListNT :: Seq :~> []-seqListNT = Nat toList+seqListNT = NT toList