Skip to content

Commit

Permalink
Start a geb reduction schema
Browse files Browse the repository at this point in the history
  • Loading branch information
mariari committed Feb 17, 2023
1 parent ca38838 commit fb275ef
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/geb/geb.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,58 @@ In category terms, `a → c^b` is isomorphic to `a → b → c`
(curry (right (comp fun (gather fst x y))))))
(prod (curry (curry (prod-left-assoc fun)))))))
(rec f (mcar dom) (mcadr dom)))))))

(defun reducer (morph &optional (seen-set (fset:empty-set)))
;; handle the piss easy cases, do the hard tracking later
(typecase-of substmorph morph
(alias (reducer morph))
(project-left morph)
(project-right morph)
(inject-left morph)
(inject-right morph)
(terminal morph)
(init morph)
(distribute morph)
(pair (pair (reducer (mcar morph))
(reducer (mcdr morph))))
(case (mcase (reducer (mcar morph))
(reducer (mcadr morph))))
(comp
(let* ((linearized (linearize-comp morph))
;; this code is absolutely horrible
(left (mvfoldr (lambda (g flist)
(let ((new-g (reducer g)))
(typecase (car flist)
(pair
(typecase new-g
(project-left (cons (mcar (car flist))
(cdr flist)))
(project-right (cons (mcdr (car flist))
(cdr flist)))
(otherwise (cons new-g flist))))
(otherwise
(cons new-g flist)))))
(butlast linearized)
(list (reducer (car (last linearized))))))
(constructed (if (cdr left)
(apply #'comp left)
(car left))))
;; g 。f
(if (fset:member? constructed seen-set)
(comp (reducer (mcar constructed)) (reducer (mcadr constructed)))
(reducer constructed (fset:with seen-set constructed)))))
(substobj morph)
(otherwise (subclass-responsibility morph))))

(defmethod fset:compare ((a <substmorph>) (b <substmorph>))
(if (and (eq (type-of a)
(type-of b))
(obj-equalp a b))
:equal
:unequal))

(defun linearize-comp (morph)
(if (typep morph 'comp)
(append (linearize-comp (mcar morph))
(linearize-comp (mcadr morph)))
(list morph)))

0 comments on commit fb275ef

Please sign in to comment.