packages feed

squares 0 → 0.0.1

raw patch · 5 files changed

+101/−15 lines, 5 filesdep ~base

Dependency ranges changed: base

Files

CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for squares +## 0.0.1 -- 2020-05-23++* Included README.+* Added `Control.Arrow.Square`.+* Removed use of BlockArguments to support older GHC versions.+ ## 0 -- 2020-05-22  * First version. Released on an unsuspecting world.
+ README.md view
@@ -0,0 +1,6 @@+# squares++`squares` is a library for working with natural transformations of type `forall a b. p a b -> q (f a) (g b)`.+These are squares in the double category of Haskell functors and profunctors.++See the `Data.Square` module for an introduction.
squares.cabal view
@@ -1,8 +1,9 @@ cabal-version:       >=1.10  name:                squares-version:             0+version:             0.0.1 synopsis:            The double category of Hask functors and profunctors+description:         A library for working with natural transformations of type @forall a b. p a b -> q (f a) (g b)@. homepage:            https://github.com/sjoerdvisscher/squares bug-reports:         https://github.com/sjoerdvisscher/squares/issues license:             BSD3@@ -11,16 +12,19 @@ maintainer:          sjoerd@w3future.com category:            Math build-type:          Simple-extra-source-files:  CHANGELOG.md+extra-source-files:+  CHANGELOG.md+  README.md  library   exposed-modules:     Data.Square                        Data.Type.List                        Data.Functor.Compose.List                        Data.Profunctor.Composition.List+                       Control.Arrow.Square+                       Control.Monad.Square                        Data.Profunctor.Square                        Data.Traversable.Square-                       Control.Monad.Square   build-depends:       base == 4.*, profunctors == 5.*   hs-source-dirs:      src   default-language:    Haskell2010
+ src/Control/Arrow/Square.hs view
@@ -0,0 +1,70 @@+{-# LANGUAGE GADTs #-}+{-# LANGUAGE DataKinds #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Arrow.Square+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  sjoerd@w3future.com+--+-----------------------------------------------------------------------------+module Control.Arrow.Square where++import Data.Square+import Data.Functor.Compose.List+import Data.Profunctor+import Data.Profunctor.Composition.List+import qualified Control.Arrow as A++-- |+-- > +-----++-- > |     |+-- > |  @--a+-- > |     |+-- > +-----++arr :: A.Arrow a => Square '[] '[a] '[] '[]+arr = Square (P . A.arr . dimap unId Id . unHom)++-- |+-- > +-----++-- > a--\  |+-- > |  @--a+-- > a--/  |+-- > +-----++(>>>) :: A.Arrow a => Square '[a, a] '[a] '[] '[]+(>>>) = Square (\(PComp p (P q)) -> P (A.arr Id A.<<< q A.<<< p A.<<< A.arr unId))++-- |+-- > +-_⊗d-++-- > |  v  |+-- > a--@--a+-- > |  v  |+-- > +-_⊗d-++second :: A.Arrow a => Square '[a] '[a] '[(,) d] '[(,) d]+second = Square (P . (A.>>> A.arr F) . (A.<<< A.arr unF) . A.second . unP)++-- |+-- > H²-⊗--H+-- > |  v  |+-- > a²-@--a+-- > |  v  |+-- > H²-⊗--H+(***) :: A.Arrow a => Square21 '[a] '[a] '[a] (,) (,)+(***) = Square $ \(P p1 :**: P p2) -> P (A.arr UncurryF A.<<< p1 A.*** p2 A.<<< A.arr curryF)++-- |+-- > +-_⊕d-++-- > |  v  |+-- > a--@--a+-- > |  v  |+-- > +-_⊕d-++right :: A.ArrowChoice a => Square '[a] '[a] '[Either d] '[Either d]+right = Square (P . (A.>>> A.arr F) . (A.<<< A.arr unF) . A.right . unP)++-- |+-- > H²-⊕--H+-- > |  v  |+-- > a²-@--a+-- > |  v  |+-- > H²-⊕--H+(+++) :: A.ArrowChoice a => Square21 '[a] '[a] '[a] Either Either+(+++) = Square $ \(P p1 :**: P p2) -> P (A.arr UncurryF A.<<< p1 A.+++ p2 A.<<< A.arr curryF)
src/Data/Square.hs view
@@ -4,7 +4,6 @@ {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TypeOperators #-}-{-# LANGUAGE BlockArguments #-} {-# LANGUAGE FlexibleContexts #-} #if __GLASGOW_HASKELL__ >= 810 {-# LANGUAGE StandaloneKindSignatures #-}@@ -46,7 +45,7 @@ -- -- The empty square is the identity transformation. emptySquare :: Square '[] '[] '[] '[]-emptySquare = Square $ dimap unId Id+emptySquare = Square (dimap unId Id)  -- | -- > +-----+@@ -62,7 +61,7 @@ -- Note that `emptySquare` is `proId` for the profunctor @(->)@. -- We don't draw a line for @(->)@ because it is the identity for profunctor composition. proId :: Profunctor p => Square '[p] '[p] '[] '[]-proId = Square $ dimap unId Id+proId = Square (dimap unId Id)  -- | -- > +--f--+@@ -78,7 +77,7 @@ -- -- We don't draw lines for the identity functor, because it is the identity for functor composition. funId :: Functor f => Square '[] '[] '[f] '[f]-funId = Square \(Hom f) -> Hom (fmap f)+funId = Square (Hom . fmap . unHom)  -- | -- > +--f--+@@ -94,7 +93,7 @@ -- @forall a. f a -> g a@. The type above you get when `fmap`ping before or after. -- (It doesn't matter which, because of naturality!) funNat :: (Functor f, Functor g) => (f ~> g) -> Square '[] '[] '[f] '[g]-funNat n = Square $ Hom . dimap unF F . (.) n . fmap . unHom+funNat n = Square (Hom . dimap unF F . (.) n . fmap . unHom)  -- | -- > +-----+@@ -107,7 +106,7 @@ -- -- Natural transformations between profunctors. proNat :: (Profunctor p, Profunctor q) => (p :-> q) -> Square '[p] '[q] '[] '[]-proNat n = Square $ P . dimap unId Id . n . unP+proNat n = Square (P . dimap unId Id . n . unP)  -- | -- > +--f--+@@ -149,10 +148,11 @@ -- > +--g--+     +--i--+       +--g--i--+ -- -- Horizontal composition of squares. `proId` is the identity of `(|||)`.+-- This is regular function composition of the underlying functions. infixl 6 ||| (|||) :: (Profunctor (PList rs), FAppend fs, FAppend gs, Functor (FList hs), Functor (FList is))       => Square ps qs fs gs -> Square qs rs hs is -> Square ps rs (fs ++ hs) (gs ++ is) -- ^-Square pq ||| Square qr = Square $ dimap funappend fappend . qr . pq+Square pq ||| Square qr = Square (dimap funappend fappend . qr . pq)  -- | -- > +--f--+@@ -171,7 +171,7 @@ infixl 5 === (===) :: (PAppend ps, PAppend qs, Profunctor (PList ss))       => Square ps qs fs gs -> Square rs ss gs hs -> Square (ps ++ rs) (qs ++ ss) fs hs -- ^-Square pq === Square rs = Square \pr -> case punappend pr of P.Procompose r p -> pappend (P.Procompose (rs r) (pq p))+Square pq === Square rs = Square (\pr -> case punappend pr of P.Procompose r p -> pappend (P.Procompose (rs r) (pq p)))   -- * Proarrow equipment@@ -189,7 +189,7 @@ -- -- A functor @f@ can be bent to the right to become the profunctor @`Star` f@. toRight :: Functor f => Square '[] '[Star f] '[f] '[]-toRight = Square \(Hom f) -> P (Star (fmap (Id . f) . unF))+toRight = Square (P . Star . (. unF) . fmap . (Id .) . unHom)  -- | -- > +--f--+@@ -200,7 +200,7 @@ -- -- A functor @f@ can be bent to the left to become the profunctor @`Costar` f@. toLeft :: Square '[Costar f] '[] '[f] '[]-toLeft = Square \(P (Costar f)) -> Hom (Id . f . unF)+toLeft = Square (Hom . dimap unF Id . runCostar . unP)  -- | -- > +-----+@@ -211,7 +211,7 @@ -- -- The profunctor @`Costar` f@ can be bent down to become the functor @f@ again. fromRight :: Functor f => Square '[] '[Costar f] '[] '[f]-fromRight = Square \(Hom f) -> P (Costar (F . fmap (f . unId)))+fromRight = Square (P . Costar . (F .) . fmap . (. unId) . unHom)  -- | -- > +-----+@@ -222,7 +222,7 @@ -- -- The profunctor @`Star` f@ can be bent down to become the functor @f@ again. fromLeft :: Square '[Star f] '[] '[] '[f]-fromLeft = Square \(P (Star f)) -> Hom (F . f . unId)+fromLeft = Square (Hom . dimap unId F . runStar . unP)  -- | -- > +-----+