From 86ad7a20d3b3bd85aafd0d280bc901d67a3ca8f2 Mon Sep 17 00:00:00 2001 From: Josh Brown Date: Thu, 19 Mar 2026 08:36:23 +1100 Subject: [PATCH] slightly neater workaround for sexp functor --- src/SExp.resi | 20 ++------------------ src/SExpFunc.res | 2 -- src/SExpJView.res | 3 ++- src/SExpJView.resi | 5 ++++- src/SExpView.res | 5 ++--- src/SExpView.resi | 2 +- src/SExpViewFunc.res | 15 +-------------- src/StringAxiomSet.res | 2 +- src/StringSExp.res | 10 ++++++---- src/StringSExp.resi | 18 ++---------------- src/StringSExpJView.res | 3 ++- src/StringSExpJView.resi | 4 +++- 12 files changed, 26 insertions(+), 63 deletions(-) diff --git a/src/SExp.resi b/src/SExp.resi index de295c4..4da7382 100644 --- a/src/SExp.resi +++ b/src/SExp.resi @@ -1,19 +1,3 @@ -// NOTE: ideally we want something like: -// include module type of SExpFunc.Make(ConstAtom) -// this doesn't work because reasons. can come back to revisit -// but i honestly suspect this is a rescript compiler bug. +module SymbolAtom: SExpFunc.ATOM with type t = string -module Atom: SExpFunc.ATOM with type t = string -type rec t = - | Atom(Atom.t) - | Compound({subexps: array}) - | Var({idx: int}) - | Schematic({schematic: int, allowed: array}) - | Ghost - -include Signatures.TERM - with type t := t - and type meta = string - and type schematic = int - and type subst = Map.t -let mapTerms: (t, t => t) => t +include module type of SExpFunc.Make(SymbolAtom) diff --git a/src/SExpFunc.res b/src/SExpFunc.res index 4967509..2a7f345 100644 --- a/src/SExpFunc.res +++ b/src/SExpFunc.res @@ -20,8 +20,6 @@ module IntCmp = Belt.Id.MakeComparable({ }) module Make = (Atom: ATOM): { - module Atom: ATOM with type t = Atom.t - type rec t = | Atom(Atom.t) | Compound({subexps: array}) diff --git a/src/SExpJView.res b/src/SExpJView.res index f034f66..c4fb49b 100644 --- a/src/SExpJView.res +++ b/src/SExpJView.res @@ -1,6 +1,7 @@ +module SExpJ = SExp module TermView = SExpView type props = { - judgment: SExp.t, + judgment: SExpJ.t, scope: array, } let make = ({judgment, scope}) => SExpView.make({term: judgment, scope}) diff --git a/src/SExpJView.resi b/src/SExpJView.resi index 2077555..67b3e2b 100644 --- a/src/SExpJView.resi +++ b/src/SExpJView.resi @@ -1 +1,4 @@ -include Signatures.JUDGMENT_VIEW with module Term := SExp and module Judgment := SExp +// really feel like this shouldn't be necessary... +module SExpJ: Signatures.JUDGMENT with module Term := SExp and type t = SExp.t + +include Signatures.JUDGMENT_VIEW with module Term := SExp and module Judgment := SExpJ diff --git a/src/SExpView.res b/src/SExpView.res index c2fb3ab..6f2a146 100644 --- a/src/SExpView.res +++ b/src/SExpView.res @@ -1,7 +1,6 @@ -module ConstAtom = SExp.Atom -module ConstAtomView: SExpViewFunc.ATOM_VIEW with module Atom := SExp.Atom = { +module SymbolAtomView: SExpViewFunc.ATOM_VIEW with module Atom := SExp.SymbolAtom = { type props = {name: string, scope: array} let make = (props: props) => React.string(props.name) } -include SExpViewFunc.Make(ConstAtom, ConstAtomView, SExp) +include SExpViewFunc.Make(SExp.SymbolAtom, SymbolAtomView, SExp) diff --git a/src/SExpView.resi b/src/SExpView.resi index ffde634..d013d82 100644 --- a/src/SExpView.resi +++ b/src/SExpView.resi @@ -1,3 +1,3 @@ -module ConstAtomView: SExpViewFunc.ATOM_VIEW with module Atom := SExp.Atom +module SymbolAtomView: SExpViewFunc.ATOM_VIEW with module Atom := SExp.SymbolAtom include Signatures.TERM_VIEW with module Term := SExp diff --git a/src/SExpViewFunc.res b/src/SExpViewFunc.res index e7e8bd8..23f89fc 100644 --- a/src/SExpViewFunc.res +++ b/src/SExpViewFunc.res @@ -7,20 +7,7 @@ module type ATOM_VIEW = { module Make = ( Atom: SExpFunc.ATOM, AtomView: ATOM_VIEW with module Atom := Atom, - SExp: { - type rec t = - | Atom(Atom.t) - | Compound({subexps: array}) - | Var({idx: int}) - | Schematic({schematic: int, allowed: array}) - | Ghost - include Signatures.TERM - with type t := t - and type meta = string - and type schematic = int - and type subst = Map.t - let mapTerms: (t, t => t) => t - }, + SExp: module type of SExpFunc.Make(Atom), ): { include Signatures.TERM_VIEW with module Term := SExp } => { diff --git a/src/StringAxiomSet.res b/src/StringAxiomSet.res index 4ac8c7d..32b4788 100644 --- a/src/StringAxiomSet.res +++ b/src/StringAxiomSet.res @@ -33,7 +33,7 @@ let varsInRule = (rule: Rule.t) => { let getSExpName = (t: SExp.t): option => switch t { - | Atom(name) => Some(name->SExp.Atom.prettyPrint(~scope=[])) + | Atom(name) => Some(name->SExp.StringSExpAtom.prettyPrint(~scope=[])) | _ => None } diff --git a/src/StringSExp.res b/src/StringSExp.res index 04c81d5..6015670 100644 --- a/src/StringSExp.res +++ b/src/StringSExp.res @@ -1,4 +1,4 @@ -type stringSExpAtom = StringS(StringAtom.t) | ConstS(SExp.Atom.t) +type stringSExpAtom = StringS(StringAtom.t) | ConstS(string) module StringSExpAtom: SExpFunc.ATOM with type t = stringSExpAtom = { type t = stringSExpAtom @@ -8,20 +8,22 @@ module StringSExpAtom: SExpFunc.ATOM with type t = stringSExpAtom = { StringAtom.parse(s, ~scope, ~gen?) ->Result.map(((r, rest)) => (StringS(r), rest)) ->Util.Result.or(() => - SExp.Atom.parse(s, ~scope, ~gen?)->Result.map(((r, rest)) => (ConstS(r), rest)) + SExp.SymbolAtom.parse(s, ~scope, ~gen?)->Result.map(((r, rest)) => (ConstS(r), rest)) ) } let prettyPrint = (s, ~scope) => switch s { | StringS(s) => StringAtom.prettyPrint(s, ~scope) - | ConstS(s) => SExp.Atom.prettyPrint(s, ~scope) + | ConstS(s) => SExp.SymbolAtom.prettyPrint(s, ~scope) } let unify = (s1, s2, ~gen=?) => switch (s1, s2) { | (StringS(s1), StringS(s2)) => StringAtom.unify(s1, s2, ~gen?)->Seq.map(subst => subst->Util.mapMapValues(v => StringS(v))) | (ConstS(s1), ConstS(s2)) => - SExp.Atom.unify(s1, s2, ~gen?)->Seq.map(subst => subst->Util.mapMapValues(v => ConstS(v))) + SExp.SymbolAtom.unify(s1, s2, ~gen?)->Seq.map(subst => + subst->Util.mapMapValues(v => ConstS(v)) + ) | (_, _) => Seq.empty } let substitute = (s, subst: subst) => diff --git a/src/StringSExp.resi b/src/StringSExp.resi index dbc8a49..cdbb3d1 100644 --- a/src/StringSExp.resi +++ b/src/StringSExp.resi @@ -1,18 +1,4 @@ -type stringSExpAtom = StringS(StringAtom.t) | ConstS(SExp.Atom.t) +type stringSExpAtom = StringS(StringAtom.t) | ConstS(string) module StringSExpAtom: SExpFunc.ATOM with type t = stringSExpAtom -type rec t = - | Atom(StringSExpAtom.t) - | Compound({subexps: array}) - | Var({idx: int}) - | Schematic({schematic: int, allowed: array}) - | Ghost - -include Signatures.TERM - with type t := t - and type meta = string - and type schematic = int - and type subst = Map.t - -module Atom: SExpFunc.ATOM with type t := StringSExpAtom.t -let mapTerms: (t, t => t) => t +include module type of SExpFunc.Make(StringSExpAtom) diff --git a/src/StringSExpJView.res b/src/StringSExpJView.res index d99cd7b..9b7c910 100644 --- a/src/StringSExpJView.res +++ b/src/StringSExpJView.res @@ -3,10 +3,11 @@ module StringAtomView: SExpViewFunc.ATOM_VIEW with module Atom := StringSExp.Str let make = ({name, scope}: props) => switch name { | StringSExp.StringS(name) => - | StringSExp.ConstS(name) => + | StringSExp.ConstS(name) => } } +module StringSExpJ = StringSExp module View = SExpViewFunc.Make(StringSExp.StringSExpAtom, StringAtomView, StringSExp) module TermView = View diff --git a/src/StringSExpJView.resi b/src/StringSExpJView.resi index efafac5..cfe9936 100644 --- a/src/StringSExpJView.resi +++ b/src/StringSExpJView.resi @@ -1 +1,3 @@ -include Signatures.JUDGMENT_VIEW with module Term := StringSExp and module Judgment := StringSExp +module StringSExpJ: Signatures.JUDGMENT with module Term := StringSExp and type t = StringSExp.t + +include Signatures.JUDGMENT_VIEW with module Term := StringSExp and module Judgment := StringSExpJ -- 2.51.2