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 Apr 27, 2023
1 parent 7863199 commit 9eca0ea
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/geb/geb.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,51 @@ In category terms, `a → c^b` is isomorphic to `a → b → c`
(error "object ~A need to be of a product type, however it is of ~A" f (dom f))
(let ((dom (dom f)))
(curry-prod f (mcar dom) (mcadr dom)))))

;; Please rewrite this code, it's horrible
(defun reducer (morph &optional (seen-set (fset:empty-set)))
;; handle the easy cases, do the hard tracking later
(typecase-of substmorph 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))))

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

0 comments on commit 9eca0ea

Please sign in to comment.