functor (empty) → 0.1.0.0
raw patch · 5 files changed
+170/−0 lines, 5 filesdep +basedep +categorysetup-changed
Dependencies added: base, category
Files
- Control/Categorical/Functor.hs +102/−0
- LICENSE +30/−0
- Prelude.hs +7/−0
- Setup.hs +2/−0
- functor.cabal +29/−0
+ Control/Categorical/Functor.hs view
@@ -0,0 +1,102 @@+{-# LANGUAGE RankNTypes,+ GADTs #-}++module Control.Categorical.Functor where++import Control.Category.Dual+import Control.Category.Groupoid+import qualified Data.Functor as Base+import Data.Functor.Compose+import Data.Functor.Identity+import Data.Functor.Const+import Data.Functor.Product+import Data.Functor.Sum+import Data.Morphism.Iso++class (Category s, Category t) => Functor (s :: α -> α -> *) (t :: β -> β -> *) (f :: α -> β) where+ map :: s a b -> t (f a) (f b)++type EndoFunctor s f = Functor s s f++infixl 4 <$>+(<$>) :: Functor s (->) f => s a b -> f a -> f b+(<$>) = map++newtype NT s f g = NT { nt :: ∀ a . s (f a) (g a) }+ deriving (Typeable)++instance Category s => Category (NT s) where+ id = NT id+ NT f . NT g = NT (f . g)++instance Groupoid s => Groupoid (NT s) where+ invert (NT f) = NT (invert f)++instance Base.Functor f => Functor (->) (->) f where map = Base.fmap++instance Category t => Functor (:~:) t f where map Refl = id++instance Functor s (->) f => Functor (NT s) (NT (->)) (Compose f) where+ map (NT f) = NT (\ (Compose x) -> Compose (f <$> x))++instance Functor (NT (->)) (NT (NT (->))) Compose where+ map (NT f) = NT (NT (\ (Compose x) -> Compose (f x)))++instance (Functor s (->) f, Functor s (->) g) => Functor s (->) (Sum f g) where+ map f (InL x) = InL (f <$> x)+ map f (InR y) = InR (f <$> y)++instance Functor (NT (->)) (NT (->)) (Sum f) where+ map (NT f) = NT (\ case InL x -> InL x+ InR y -> InR (f y))++instance Functor (NT (->)) (NT (NT (->))) Sum where+ map (NT f) = NT (NT (\ case InL x -> InL (f x)+ InR y -> InR y))++instance (Functor s (->) f, Functor s (->) g) => Functor s (->) (Product f g) where+ map f (Pair x y) = Pair (f <$> x) (f <$> y)++instance Functor (NT (->)) (NT (->)) (Product f) where+ map (NT f) = NT (\ (Pair x y) -> Pair x (f y))++instance Functor (NT (->)) (NT (NT (->))) Product where+ map (NT f) = NT (NT (\ (Pair x y) -> Pair (f x) y))++instance Category s => Functor s (->) (Const a) where+ map _ (Const a) = Const a++instance Functor (->) (NT (->)) Const where+ map f = NT (\ (Const a) -> Const (f a))++instance Functor (->) (->) Identity where+ map f (Identity a) = Identity (f a)++instance Category s => Functor s (->) Proxy where+ map _ Proxy = Proxy++instance Functor (->) (->) ((,) a) where+ map f (a, b) = (a, f b)++instance Functor (->) (NT (->)) (,) where+ map f = NT (\ (a, b) -> (f a, b))++instance Functor (->) (->) (Either a) where+ map _ (Left a) = Left a+ map f (Right b) = Right (f b)++instance Functor (->) (NT (->)) Either where+ map f = NT (\ case Left a -> Left (f a)+ Right b -> Right b)++instance Category s => Functor s (->) (s a) where+ map = (.)++instance Category s => Functor (Dual s) (NT (->)) s where+ map (Dual f) = NT (. f)++instance Functor s t f => Functor (Iso s) t f where+ map (Iso f _) = map f++instance Functor s t f => Functor (Iso s) (Dual t) f where+ map (Iso _ f') = Dual (map f')
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2017, M Farkas-Dyck++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of M Farkas-Dyck nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Prelude.hs view
@@ -0,0 +1,7 @@+module Prelude (module Control.Category,+ module Data.Either,+ module Data.Typeable) where++import Control.Category+import Data.Either+import Data.Typeable
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ functor.cabal view
@@ -0,0 +1,29 @@+name: functor+version: 0.1.0.0+synopsis: Functors+-- description: +license: BSD3+license-file: LICENSE+author: M Farkas-Dyck+maintainer: m.farkasdyck@gmail.com+-- copyright: +category: Control, Math+build-type: Simple+cabal-version: >=1.10++library+ exposed-modules: Control.Categorical.Functor+ other-modules: Prelude+ -- other-extensions: + build-depends: base >=4.11 && <4.12+ , category >=0.1.1 && <0.2+ -- hs-source-dirs: + default-language: Haskell2010+ default-extensions: LambdaCase+ , UnicodeSyntax+ , PolyKinds+ , ConstraintKinds+ , MultiParamTypeClasses+ , FlexibleContexts+ , FlexibleInstances+ , DeriveDataTypeable