Last active
February 3, 2018 23:27
-
-
Save CodaFi/4d0ce6a3cc0cb1085720 to your computer and use it in GitHub Desktop.
Because I could
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Category.swift | |
// Swift_Extras | |
// | |
// Created by Robert Widmann on 9/7/14. | |
// Copyright (c) 2014 Robert Widmann. All rights reserved. | |
// | |
import Foundation | |
/// A Category is an algebraic structure consisting of a set of objects and a set of morphisms | |
/// between those objects. Each object includes an identity morphism, and composition of morphisms | |
/// is the primary reason categories are such powerful abstractions. | |
/// | |
/// Here, a Category is some class of Kind * -> * -> * that you can think of as modelling an "arrow" | |
/// from A -> B. This means that if we provide a composition function, `•`, we can hook up | |
/// Categories from A -> B with Categories from B -> C and get Categories from A -> C. This | |
/// function is also called >>>. | |
public protocol Category { | |
/// Source | |
typealias A | |
/// Target | |
typealias B | |
/// Other Target; Usually Any | |
typealias C | |
/// The identity category | |
typealias CAA = K2<A, A> | |
/// Our Category | |
typealias CAB = K2<A, B> | |
/// A Category we can compose with. | |
typealias CBC = K2<B, C> | |
/// The composition of this Category with the Category above. | |
typealias CAC = K2<A, C> | |
/// The identity morphism. | |
class func id() -> CAA | |
/// Composition of categories. | |
/// | |
/// If you peek behind the types, it's just plain old composition. | |
func •(c : CBC, c2 : CAB) -> CAC | |
/// Forward composition. | |
/// | |
/// Usually an alias for • | |
func >>> (CAB, CBC) -> CAC | |
/// Backwards composition. | |
/// | |
/// Forward composition with the parameters flipped. | |
func <<< (CBC, CAB) -> CAC | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment