Skip to content

Put projectors into web then quickly pull it out #1620

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

Draft
wants to merge 2 commits into
base: semantics
Choose a base branch
from

Conversation

disconcision
Copy link
Member

This represents a trial attempt to move all of core (after semantics was extracted) into web, and then pull projectors out (wanted to get an idea if a functorial approach might work well here). I created a module type representing projectors current syntax dependency, to use as a kind of stand-in for a future Editor.t dependency:

module type Syntax = {
  type segment;
  let unparenthesize: segment => segment;
  let to_string: segment => string;
  let sort_of: segment => Sort.t;
};

(these are all things projectors currently use, somewhat incidentally)

Then i turned ProjectorBase.Projector into a functor taking that as an argument:

module type Projector =
  (Syntax: Syntax) =>
   {
    /* The internal model type of the projector which will
     * be serialized and persisted. Use `unit` if you don't
     * need other state beyond the underlying syntax */
    [@deriving (show({with_path: false}), sexp, yojson)]
    type model;
    ...

and the implementations get functorized as well:

module Make: Projector =
  (
    Syntax: {
      type segment;
      let unparenthesize: segment => segment;
      let sort_of: segment => Semantics.Sort.t;
    },
  ) => {
    [@deriving (show({with_path: false}), sexp, yojson)]
    type model = t;
    ...

BUT with the above i can't figure out how to reinstate the GADT type constraints we previouslu introduced here e.g. with model = ProjectorCore.Kind.fold_model

I got as far as trying to functorize the to_module functionality:

module Init = (Syntax: Syntax) => {
  let to_module =
      (type a, kind: ProjectorCore.Kind.gadt(a))
      : (module ProjectorInstance with type model = a) => {
    switch (kind) {
    | Fold => (module FoldProj.Make(Syntax))
    | Info => (module TypeProj.Make(Syntax))
    ...

but now I start running into, I think, that effect of removing that type constraint:

This expression has type
  (module ProjectorInstance with type model = FoldProj.Make(Syntax).model)
but an expression was expected of type
  (module ProjectorInstance with type model = a)
Type FoldProj.Make(Syntax).model is not compatible with type a = FoldProj.t

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

Successfully merging this pull request may close these issues.

1 participant