Skip to content

Packages for studying the connections between Qi and Category Theory.

License

Notifications You must be signed in to change notification settings

NoahStoryM/qi-cat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

qi-cat

Table of Contents

Libs

(require qi/sum)

Qi with covalues (sum).

(require qi/cat)

A experimental library for studying the connections between Qi and Category Theory.

Category Theory Connections

QiCategory Theory
(~> f g)g∘f
(==* f g) / (==+ f g)f×g / f+g
(-< f g) / (>- f g)<f,g> / <f¦g>
△ / ▷->product / sum->
▽ / ◁product->* / *->sum
⏚ / ≂->1 / 0->
n> / n<proj_n / inj_n
fanout / fanin<id,id,…> / <id¦id¦…>
>< / <>

Examples

(define eval
  (λ (exp env)
    (cond
      [(self-evaluating? exp) exp]
      [(variable? exp) (lookup-variable-value exp env)]
      [(quoted? exp) (text-of-quotation exp)]
      [(assignment? exp) (eval-assignment exp env)]
      [(definition? exp) (eval-definition exp env)]
      [(if? exp) (eval-if exp env)]
      [(lambda? exp)
       (make-procedure
        (lambda-parameters exp)
        (lambda-body exp)
        env)]
      [(begin? exp) (eval-sequence (begin-actions exp) env)]
      [(cond? exp) (eval (cond->if exp) env)]
      [(application? exp)
       (apply (eval (operator exp) env)
         (list-of-values (operands exp) env))]
      [else (error "Unknown expression type -- EVAL" exp)])))


(define eval
  (λ (exp env)
    (switch (exp)
      [self-evaluating? _]
      [variable? (lookup-variable-value env)]
      [quoted? text-of-quotation]
      [assignment? (eval-assignment env)]
      [definition? (eval-definition env)]
      [if? (eval-if env)]
      [lambda?
       (~> (-< lambda-parameters
               lambda-body)
           (make-procedure env))]
      [begin? (~> begin-actions (eval-sequence env))]
      [cond? (~> cond->if (eval env))]
      [application?
       (~> (-< (~> operator (eval env))
               (~> operands (list-of-values env)))
           (esc apply))]
      [else (error "Unknown expression type -- EVAL" _)])))


;; sexp->sum : S-Exp ->   Self-Exp
;;                      + Var-Exp
;;                      + Quoted-Exp
;;                      + Assign-Exp
;;                      + Definition-Exp
;;                      + If-Exp
;;                      + Lambda-Exp
;;                      + Begin-Exp
;;                      + Cond-Exp
;;                      + Application-Exp
;;                      + Else
(define sexp->sum
  (☯
    (~> (-< _
            (=< self-evaluating?
                variable?
                quoted?
                assignment?
                definition?
                if?
                lambda?
                begin?
                cond?
                application?
                #t))
        (<<< 2))))

(define-flow (eval exp env)
  (~>
    (==* sexp->sum _)
    (<<< 1)
    (>-
      1>
      lookup-variable-value
      (~> 1> text-of-quotation)
      eval-assignment
      eval-definition
      eval-if
      (~> (==* (-< lambda-parameters lambda-body) _) make-procedure)
      (~> (==* begin-actions _) eval-sequence)
      (~> (==* cond->if _) eval)
      (~> (-< (~> (==* operator _) eval)
              (~> (==* operands _) list-of-values))
          (esc apply))
      (~> 1> (error "Unknown expression type -- EVAL" _)))))

About

Packages for studying the connections between Qi and Category Theory.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages