Skip to content

Commit 318ee85

Browse files
committed
Merge pull request #79 from purescript/natendo
Add natural transformation synonym & operator
2 parents e277097 + 20004f9 commit 318ee85

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Data/NaturalTransformation.purs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module Data.NaturalTransformation where
2+
3+
-- | A type for natural transformations.
4+
-- |
5+
-- | A natural transformation is a mapping between type constructors of kind
6+
-- | `* -> *` where the mapping operation has no ability to manipulate the
7+
-- | inner values.
8+
-- |
9+
-- | An example of this is the `fromFoldable` function provided in
10+
-- | `purescript-lists`, where some foldable structure containing values of
11+
-- | type `a` is converted into a `List a`.
12+
-- |
13+
-- | The definition of a natural transformation in category theory states that
14+
-- | `f` and `g` should be functors, but the `Functor` constraint is not
15+
-- | enforced here; that the types are of kind `* -> *` is enough for our
16+
-- | purposes.
17+
type NaturalTransformation f g = forall a. f a -> g a
18+
19+
infixr 4 type NaturalTransformation as ~>

src/Prelude.purs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Prelude
1515
, module Data.Function
1616
, module Data.Functor
1717
, module Data.HeytingAlgebra
18+
, module Data.NaturalTransformation
1819
, module Data.Ord
1920
, module Data.Ordering
2021
, module Data.Ring
@@ -42,6 +43,7 @@ import Data.Field (class Field)
4243
import Data.Function (const, flip, ($), (#))
4344
import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>))
4445
import Data.HeytingAlgebra (class HeytingAlgebra, conj, disj, not, (&&), (||))
46+
import Data.NaturalTransformation (type (~>))
4547
import Data.Ord (class Ord, compare, (<), (<=), (>), (>=), comparing, min, max, clamp, between)
4648
import Data.Ordering (Ordering(..))
4749
import Data.Ring (class Ring, negate, sub, (-))

0 commit comments

Comments
 (0)