Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensions through Mixins #64

Closed
mariari opened this issue Feb 13, 2023 · 1 comment
Closed

Extensions through Mixins #64

mariari opened this issue Feb 13, 2023 · 1 comment
Labels

Comments

@mariari
Copy link
Member

mariari commented Feb 13, 2023

The central question of open extension should rest on:

Should we

  1. subclass extensions like Add modular-arithmetic types to Geb external API #61, saying this is a subclass of <substmorph>
  2. extend with a mixin service architecture?

Upon reflection of our current architecture I suggest we follow course 2., and in essence 1. is just 2. in disguise.

With 1. <substmorph> is already an abstract class, meaning it is in essence already an interface.

We can setup this architecture as follows:

  • cat-morph
  • cat-obj

Are the new interfaces. They may pledge a core set of functions like:

(dom ...)
(codom ...)
(curry ...)
etc. etc. etc.

Along with #63 we can enforce this through our interface idea. We can use stealth-mixins to implement this fact after class creation

Now, if we want to extend our core category, then we just implement the cat-morph and cat-obj interfaces.

Further the extensions that <substmorph> implements many may not be available in every extension set, and thus we can implement those as part of a new interface set of extensions.

For type checking purposes, if one makes an ADT with slots of a certain type, instead of making them on your concrete subclass, instead make them on the open type cat-morph and cat-obj instead. Our code was previously already doing this with <substmoprh and <substobj>

Thus we should change

(defclass inject-left (<substmorph>)
  ((mcar :initarg :mcar
         :accessor mcar
         :type <substobj>
         :documentation "")
   (mcadr :initarg :mcadr
          :accessor mcadr
          :type <substobj>
          :documentation ""))

into

(defclass inject-left (<substmorph>)
  ((mcar :initarg :mcar
         :accessor mcar
         :type cat-obj
         :documentation "")
   (mcadr :initarg :mcadr
          :accessor mcadr
          :type cat-obj
          :documentation ""))

One conceit of this style of code is that any recursive function must be apart of an interface, but that is fine, we already do that.

(defmethod so-card-alg ((obj <substobj>))
  ;; we don't use the cata morphism so here we are. Doesn't give me
  ;; much extra
  (match-of geb:substobj obj
    (geb:alias        (so-card-alg (obj obj)))
    ((geb:prod a b)   (* (so-card-alg a)
                         (so-card-alg b)))
    ((geb:coprod a b) (+ (so-card-alg a)
                         (so-card-alg b)))
    (geb:so0          1)
    (geb:so1          1)))

Perhaps we can make some general recursive functions, so we don't have to tediously do this for every core functionality, meaning we should be able to derive most of these functions from the core interface. I think @rokopt would have some good ideas on recurses for the data type in particular.

@mariari mariari changed the title Extensions via mixins? Extensions through Mixins Feb 13, 2023
@mariari
Copy link
Member Author

mariari commented Mar 6, 2023

This task is mostly done, with mixins being in the codebase, but the interface isn't concrete yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant