Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
GHC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kraai
GHC
Commits
fbbbd010
Commit
fbbbd010
authored
9 months ago
by
Daan Rijks
Committed by
Marge Bot
5 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Expand the haddocks for Control.Category
parent
5f67db48
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libraries/base/src/Control/Category.hs
+18
-1
18 additions, 1 deletion
libraries/base/src/Control/Category.hs
libraries/ghc-internal/src/GHC/Internal/Control/Category.hs
+54
-8
54 additions, 8 deletions
libraries/ghc-internal/src/GHC/Internal/Control/Category.hs
with
72 additions
and
9 deletions
libraries/base/src/Control/Category.hs
+
18
−
1
View file @
fbbbd010
...
...
@@ -11,9 +11,26 @@
--
module
Control.Category
(
Category
(
..
)
(
-- * Class
Category
(
..
)
-- * Combinators
,
(
<<<
)
,
(
>>>
)
-- $namingConflicts
)
where
import
GHC.Internal.Control.Category
-- $namingConflicts
--
-- == A note on naming conflicts
--
-- The methods from 'Category' conflict with 'Prelude.id' and 'Prelude..' from the
-- prelude; you will likely want to either import this module qualified, or hide the
-- prelude functions:
--
-- @
-- import "Prelude" hiding (id, (.))
-- @
This diff is collapsed.
Click to expand it.
libraries/ghc-internal/src/GHC/Internal/Control/Category.hs
+
54
−
8
View file @
fbbbd010
...
...
@@ -28,17 +28,61 @@ import GHC.Internal.Data.Coerce (coerce)
infixr
9
.
infixr
1
>>>
,
<<<
-- | A class for categories.
Instances should satisfy the laws
-- | A class for categories.
--
-- [Right identity] @f '.' 'id' = f@
-- [Left identity] @'id' '.' f = f@
-- [Associativity] @f '.' (g '.' h) = (f '.' g) '.' h@
-- In mathematics, a /category/ is defined as a collection of /objects/ and a collection
-- of /morphisms/ between objects, together with an /identity morphism/ 'id' for every
-- object and an operation '(.)' that /composes/ compatible morphisms.
--
-- This class is defined in an analogous way. The collection of morphisms is represented
-- by a type parameter @cat@, which has kind @k -> k -> 'Data.Kind.Type'@ for some kind variable @k@
-- that represents the collection of objects; most of the time the choice of @k@ will be
-- 'Data.Kind.Type'.
--
-- ==== __Examples__
--
-- As the method names suggest, there's a category of functions:
--
-- @
-- instance Category '(->)' where
-- id = \\x -> x
-- f . g = \\x -> f (g x)
-- @
--
-- Using the `TypeData` language extension, we can also make a category where `k` isn't
-- `Type`, but a custom kind `Door` instead:
--
-- @
-- type data Door = DoorOpen | DoorClosed
--
-- data Action (before :: Door) (after :: Door) where
-- DoNothing :: Action door door
-- OpenDoor :: Action start DoorClosed -> Action start DoorOpen
-- CloseDoor :: Action start DoorOpen -> Action start DoorClosed
--
-- instance Category Action where
-- id = DoNothing
--
-- DoNothing . action = action
-- OpenDoor rest . action = OpenDoor (rest . action)
-- CloseDoor rest . action = CloseDoor (rest . action)
-- @
--
class
Category
cat
where
-- | the identity morphism
-- | The identity morphism. Implementations should satisfy two laws:
--
-- [Right identity] @f '.' 'id' = f@
-- [Left identity] @'id' '.' f = f@
--
-- These essentially state that 'id' should "do nothing".
id
::
cat
a
a
-- | morphism composition
-- | Morphism composition. Implementations should satisfy the law:
--
-- [Associativity] @f '.' (g '.' h) = (f '.' g) '.' h@
--
-- This means that the way morphisms are grouped is irrelevant, so it is unambiguous
-- to write a composition of morphisms as @f '.' g '.' h@, without parentheses.
(
.
)
::
cat
b
c
->
cat
a
b
->
cat
a
c
{-# RULES
...
...
@@ -70,11 +114,13 @@ instance Category Coercion where
id
=
Coercion
(
.
)
Coercion
=
coerce
-- | Right-to-left composition
-- | Right-to-left composition. This is a synonym for '(.)', but it can be useful to make
-- the order of composition more apparent.
(
<<<
)
::
Category
cat
=>
cat
b
c
->
cat
a
b
->
cat
a
c
(
<<<
)
=
(
.
)
-- | Left-to-right composition
-- | Left-to-right composition. This is useful if you want to write a morphism as a
-- pipeline going from left to right.
(
>>>
)
::
Category
cat
=>
cat
a
b
->
cat
b
c
->
cat
a
c
f
>>>
g
=
g
.
f
{-# INLINE (>>>) #-}
-- see Note [INLINE on >>>]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment