natural-transformation 0.2 → 0.3
raw patch · 8 files changed
+118/−86 lines, 8 filesdep ~basedep ~natural-transformationdep ~tastynew-uploader
Dependency ranges changed: base, natural-transformation, tasty
Files
- CHANGELOG.md +7/−0
- README.md +3/−1
- natural-transformation.cabal +14/−8
- src/Control/Natural.hs +36/−33
- src/Control/Natural/RULES.hs +32/−0
- src/Control/Object.hs +25/−0
- src/Control/Transformation.hs +0/−42
- tests/Properties.hs +1/−2
CHANGELOG.md view
@@ -1,3 +1,10 @@+# 0.3+* Adding Object+* Rolled Control.Transformation into Control.Natural+* Added RULES module+* Required GHC 7.8 or greater+* `Semigroup` instance for `(:~>)` on GHC 8.0 and up+ # 0.2 * Require GHC 7.6 or greater * Exposed `~>` type synonym
README.md view
@@ -1,3 +1,5 @@ # natural-transformation [](http://hackage.haskell.org/package/natural-transformation) [](https://travis-ci.org/ku-fpg/natural-transformation) -A natural transformation transforms a container `f a` into another container `g a` while preserving the internal structure. Natural transformations act as functor morphisms in category theory. Technically, `f` and `g` should be functors, but we allow any correctly-shaped structure.+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,9 +1,12 @@ name: natural-transformation-version: 0.2+version: 0.3 synopsis: A natural transformation package. description: A natural transformation transforms a container @f a@ into another- container @g a@ while preserving the internal structure. Natural- transformations act as functor morphisms in category theory.+ container @g a@. Natural transformations act as functor morphisms+ in category theory.+ .+ The naming of '~>', ':~>' and '$$' were taken,+ with permission, from Edward Kmett's @indexed@ package. homepage: https://github.com/ku-fpg/natural-transformation bug-reports: https://github.com/ku-fpg/natural-transformation/issues license: BSD3@@ -15,6 +18,7 @@ category: Control build-type: Simple extra-source-files: CHANGELOG.md, README.md+tested-with: GHC == 7.8.4, GHC == 7.10.3 cabal-version: >= 1.10 source-repository head@@ -23,8 +27,10 @@ library exposed-modules: Control.Natural- Control.Transformation- build-depends: base >= 4.6 && < 5+ Control.Natural.RULES+ Control.Object+ + build-depends: base >= 4.7 && < 5 hs-source-dirs: src default-language: Haskell2010 ghc-options: -Wall@@ -32,11 +38,11 @@ test-suite natural-transformation-properties type: exitcode-stdio-1.0 main-is: Properties.hs- build-depends: base >= 4.6 && < 5+ build-depends: base >= 4.7 && < 5 , containers >= 0.1 && < 0.6- , natural-transformation == 0.2+ , natural-transformation == 0.3 , quickcheck-instances >= 0.1 && < 0.4- , tasty >= 0.8 && < 0.11+ , tasty >= 0.8 && < 0.12 , tasty-quickcheck >= 0.8 && < 0.9 hs-source-dirs: tests default-language: Haskell2010
src/Control/Natural.hs view
@@ -1,22 +1,13 @@ {-# LANGUAGE CPP #-}+{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE GADTs #-}-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE TypeOperators #-}--#if MIN_VERSION_base(4,7,0)-# define LANGUAGE_PolyKinds+{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE PolyKinds #-}-#endif--#if __GLASGOW_HASKELL__ >= 708-# define LANGUAGE_DeriveDataTypeable-{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE RankNTypes #-} {-# LANGUAGE Safe #-}-#else-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE Trustworthy #-}-#endif+{-# LANGUAGE TypeOperators #-} {-| Module: Control.Natural@@ -25,21 +16,29 @@ Maintainer: Andy Gill Stability: Experimental -A data type for natural transformations.+A data type and class for natural transformations. -}-module Control.Natural ((~>)(), (:~>)(..)) where+module Control.Natural+ ( -- * Type Synonym for a Natural Transformation+ type (~>)+ -- * Newtype for a Natural Transformation+ , (:~>)(..)+ -- * Class for Natural Transformations+ , Transformation(..)+ ) where -#if defined(LANGUAGE_PolyKinds) import qualified Control.Category as C (Category(..))-#endif #if !(MIN_VERSION_base(4,8,0)) import Data.Monoid (Monoid(..)) #endif+#if MIN_VERSION_base(4,9,0)+import Data.Semigroup (Semigroup(..))+#endif import Data.Typeable ------------------------------------------------------------------------------ Code adapted, with permission, from Edward Kmett's @indexed@ package.+-- Naming of ~>, :~> and $$ are taken (with permission) from Edward Kmett's @indexed@ package. --------------------------------------------------------------------------- infixr 0 ~>@@ -49,27 +48,31 @@ infixr 0 :~>, $$ -- | A natural transformation suitable for storing in a container. newtype f :~> g = Nat { ($$) :: f ~> g }-#if defined(LANGUAGE_DeriveDataTypeable) deriving Typeable-#else-instance (Typeable1 f, Typeable1 g) => Typeable (f :~> g) where- typeOf _ = mkTyConApp natTyCon [typeOf1 (undefined :: f a), typeOf1 (undefined :: g a)] -natTyCon :: TyCon-# if MIN_VERSION_base(4,4,0)-natTyCon = mkTyCon3 "natural-transformation" "Control.Natural" ":~>"-# else-natTyCon = mkTyCon ":~>"-# endif-{-# NOINLINE natTyCon #-}-#endif--#if defined(LANGUAGE_PolyKinds) instance C.Category (:~>) where id = Nat id Nat f . Nat g = Nat (f . g)++#if MIN_VERSION_base(4,9,0)+instance f ~ g => Semigroup (f :~> g) where+ Nat f <> Nat g = Nat (f . g) #endif instance f ~ g => Monoid (f :~> g) where mempty = Nat id mappend (Nat f) (Nat g) = Nat (f . g)++infix 0 #+-- | A (natural) transformation is inside @t@, and contains @f@ and @g@+-- (typically 'Functor's).+--+-- The order of arguments allows the use of @GeneralizedNewtypeDeriving@ to wrap+-- a ':~>', but maintain the 'Transformation' constraint. Thus, @#@ can be used+-- on abstract data types.+class Transformation f g t | t -> f g where+ -- | The invocation method for a natural transformation.+ (#) :: t -> f a -> g a++instance Transformation f g (f :~> g) where+ Nat f # g = f g
+ src/Control/Natural/RULES.hs view
@@ -0,0 +1,32 @@+{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE Trustworthy #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}++{-|+Module: Control.Transformation.RULES+Copyright: (C) 2015 The University of Kansas+License: BSD-style (see the file LICENSE)+Maintainer: Andy Gill+Stability: Experimental++= GHC RULE for Natural Transformation+++@+ RULES "natural free theorem" [~]+ forall h (r :: (Functor f, Functor g, Transformation f g t) => t) .+ fmap h . (r \#) = (r #) . fmap h+@++-}+module Control.Natural.RULES () where++import Control.Natural++{-# RULES "natural free theorem" [~]+ forall h (r :: (Functor f, Functor g, Transformation f g t) => t) .+ fmap h . (r #) = (r #) . fmap h+ #-}+
+ src/Control/Object.hs view
@@ -0,0 +1,25 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE Safe #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE RankNTypes #-}++{-|+Module: Control.Object+Copyright: (C) 2015 The University of Kansas+License: BSD-style (see the file LICENSE)+Maintainer: Andy Gill+Stability: Experimental++An Object type, which is a natural transformation into the 'IO' monad.+-}++module Control.Object (Object(..), (#)) where++import Control.Natural++-- | An 'Object' is a natural transformation from a given 'Functor' 'f', to 'IO'.+newtype Object f = Object (f ~> IO)++instance Transformation f IO (Object f) where+ Object f # g = Nat f # g
− src/Control/Transformation.hs
@@ -1,42 +0,0 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE FunctionalDependencies #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE Safe #-}-{-# LANGUAGE TypeOperators #-}--#if MIN_VERSION_base(4,7,0)-{-# LANGUAGE PolyKinds #-}-#endif--{-|-Module: Control.Transformation-Copyright: (C) 2015 The University of Kansas-License: BSD-style (see the file LICENSE)-Maintainer: Andy Gill-Stability: Experimental--A type class for transformations.--}-module Control.Transformation (Transformation(..)) where--import Control.Natural ((:~>)(..))--infixr 0 #--- | A (natural) transformation is inside @t@, and contains @f@ and @g@--- (typically 'Functor's).--- --- The order of arguments allows the use of @GeneralizedNewtypeDeriving@ to wrap--- a ':~>', but maintain the 'Transformation' constraint. Thus, @#@ can be used--- on abstract data types.-class Transformation f g t | t -> f g where- -- | The invocation method for a natural transformation.- (#) :: t -> f a -> g a---- {-# RULES "natural free theorem" [~] --- forall h (r :: (Functor f, Functor g, Transformation f g t) => t) . --- fmap h . (r #) = (r #) . fmap h --- #-}--instance Transformation f g (f :~> g) where- Nat f # g = f g
tests/Properties.hs view
@@ -11,8 +11,7 @@ -} module Main (main) where -import Control.Natural ((:~>)(..))-import Control.Transformation (Transformation(..))+import Control.Natural import Data.Foldable (toList) #if !(MIN_VERSION_base(4,8,0))