Skip to content

Commit

Permalink
Add Semigroupoid type-class
Browse files Browse the repository at this point in the history
  • Loading branch information
YoEight committed Sep 7, 2013
1 parent 7b05453 commit 641ddef
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
30 changes: 7 additions & 23 deletions frege/control/Category.fr
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
package frege.control.Category
inline (F., F.id)
package frege.control.Category
inline (F.id)
where

import frege.Prelude hiding (id, .) -- will not be necessary
import frege.Prelude hiding (id) -- will not be necessary
import frege.control.Semigroupoid

private type F = (->)

--- A class for categories. id and (.) must form a monoid.
class Category f where
class Category (Semigroupoid f) => f where
--- the identity morphism
id :: f a a

--- morphism composition
(.) :: f b c -> f a b -> f a c

infixr 1 `>>>`
infixr 1 `<<<`

--- Right-to-left composition
(<<<) :: Category f => f b c -> f a b -> f a c
(<<<) = (.)

--- Left-to-right composition
(>>>) :: Category f => f a b -> f b c -> f a c
f >>> g = g . f
id :: f a a

instance Category (->) where
id = \x -> x

f . g = \a -> f (g a)
id = \x -> x
25 changes: 25 additions & 0 deletions frege/control/Semigroupoid.fr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package frege.control.Semigroupoid
inline (F.•)
where

import frege.Prelude hiding (.)

private type F = (->)

class Semigroupoid f where
--- morphism composition
(.) :: f b c -> f a b -> f a c

infixr 1 `>>>`
infixr 1 `<<<`

--- Right-to-left composition
(<<<) :: Semigroupoid f => f b c -> f a b -> f a c
(<<<) = (.)

--- Left-to-right composition
(>>>) :: Semigroupoid f => f a b -> f b c -> f a c
f >>> g = g . f

instance Semigroupoid (->) where
f . g = \a -> f (g a)

0 comments on commit 641ddef

Please sign in to comment.