···11module type ATOM = SExpFunc.ATOM
22exception RawVarOrSchematic
3344-module MakeAtom = (Left: ATOM, Right: ATOM): {
44+module MakeAtom = (Left: AtomDef.COERCIBLE_ATOM, Right: AtomDef.COERCIBLE_ATOM): {
55 type base =
66 | Left(Left.t)
77 | Right(Right.t)
···1111 | Schematic({schematic: int, allowed: array<int>})
1212 include ATOM with type t = base
1313 let match: (t, Left.t => 'a, Right.t => 'a) => 'a
1414-} => {
1515- type base =
1616- | Left(Left.t)
1717- | Right(Right.t)
1818- | Var({idx: int})
1919- | Schematic({schematic: int, allowed: array<int>})
2020- type t = base
2121- type subst = Map.t<int, t>
2222- type gen = ref<int>
2323- let match = (t, leftBranch: Left.t => 'a, rightBranch: Right.t => 'a): 'a =>
2424- switch t {
2525- | Left(s) => leftBranch(s)
2626- | Right(s) => rightBranch(s)
2727- | _ => throw(RawVarOrSchematic)
2828- }
2929- let parse = (s, ~scope, ~gen: option<gen>=?) => {
3030- Left.parse(s, ~scope, ~gen?)
3131- ->Result.map(((r, rest)) => (Left(r), rest))
3232- ->Util.Result.or(() =>
3333- Right.parse(s, ~scope, ~gen?)->Result.map(((r, rest)) => (Right(r), rest))
3434- )
3535- }
3636- let prettyPrint = (s, ~scope) =>
3737- s->match(left => Left.prettyPrint(left, ~scope), right => Right.prettyPrint(right, ~scope))
3838- let unify = (s1, s2, ~gen=?) =>
3939- switch (s1, s2) {
4040- | (Left(s1), Left(s2)) =>
4141- Left.unify(s1, s2, ~gen?)->Seq.map(subst => subst->Util.mapMapValues(v => Left(v)))
4242- | (Right(s1), Right(s2)) =>
4343- Right.unify(s1, s2, ~gen?)->Seq.map(subst => subst->Util.mapMapValues(v => Right(v)))
4444- | (_, _) => Seq.empty
4545- }
4646- let substitute = (s, subst: subst) => {
4747- s->match(
4848- left => {
4949- let leftSubs = subst->Util.Map.filterMap((_, v) =>
5050- switch v {
5151- | Left(s) => Some(s)
5252- | _ => None
5353- }
5454- )
5555- Left(Left.substitute(left, leftSubs))
5656- },
5757- right => {
5858- let rightSubs = subst->Util.Map.filterMap((_, v) =>
5959- switch v {
6060- | Right(s) => Some(s)
6161- | _ => None
6262- }
6363- )
6464- Right(Right.substitute(right, rightSubs))
6565- },
6666- )
6767- }
6868- let upshift = (s, amount: int, ~from=?) =>
6969- s->match(
7070- left => Left(left->Left.upshift(amount, ~from?)),
7171- right => Right(right->Right.upshift(amount, ~from?)),
7272- )
7373- let lowerVar = idx => Some(Var({idx: idx}))
7474- let lowerSchematic = (schematic, allowed) => Some(Schematic({schematic, allowed}))
7575- let substDeBruijn = (s, substs: array<option<t>>, ~from=?) =>
7676- s->match(
7777- left => {
7878- let leftSubs = substs->Array.map(s =>
7979- switch s {
8080- | Some(Left(s)) => Some(s)
8181- | Some(Var({idx})) => Left.lowerVar(idx)
8282- | Some(Schematic({schematic, allowed})) => Left.lowerSchematic(schematic, allowed)
8383- | _ => None
8484- }
8585- )
8686- Left(Left.substDeBruijn(left, leftSubs, ~from?))
8787- },
8888- right => {
8989- let rightSubs = substs->Array.map(s =>
9090- switch s {
9191- | Some(Right(s)) => Some(s)
9292- | Some(Var({idx})) => Right.lowerVar(idx)
9393- | Some(Schematic({schematic, allowed})) => Right.lowerSchematic(schematic, allowed)
9494- | _ => None
9595- }
9696- )
9797- Right(Right.substDeBruijn(right, rightSubs, ~from?))
9898- },
9999- )
100100- let concrete = s => s->match(Left.concrete, Right.concrete)
101101-}
1414+} => AtomDef.CombineAtom(Left, Right)
1021510316module type ATOM_VIEW = SExpViewFunc.ATOM_VIEW
10417module MakeAtomView = (
105105- Left: ATOM,
1818+ Left: AtomDef.COERCIBLE_ATOM,
10619 LeftView: ATOM_VIEW with module Atom := Left,
107107- Right: ATOM,
2020+ Right: AtomDef.COERCIBLE_ATOM,
10821 RightView: ATOM_VIEW with module Atom := Right,
10922 Combined: module type of MakeAtom(Left, Right),
11023): {
···11932}
1203312134module MakeAtomAndView = (
122122- Left: ATOM,
3535+ Left: AtomDef.COERCIBLE_ATOM,
12336 LeftView: ATOM_VIEW with module Atom := Left,
124124- Right: ATOM,
3737+ Right: AtomDef.COERCIBLE_ATOM,
12538 RightView: ATOM_VIEW with module Atom := Right,
12639) => {
12740 module Atom = MakeAtom(Left, Right)
+1-14
src/SExpFunc.res
···11exception SubstNotCompatible(string)
2233-module type ATOM = {
44- type t
55- type subst = Map.t<int, t>
66- let unify: (t, t, ~gen: ref<int>=?) => Seq.t<subst>
77- let prettyPrint: (t, ~scope: array<string>) => string
88- let parse: (string, ~scope: array<string>, ~gen: ref<int>=?) => result<(t, string), string>
99- let substitute: (t, subst) => t
1010- let upshift: (t, int, ~from: int=?) => t
1111- // used for when trying to substitute a variable of the wrong type
1212- let lowerVar: int => option<t>
1313- let lowerSchematic: (int, array<int>) => option<t>
1414- let substDeBruijn: (t, array<option<t>>, ~from: int=?) => t
1515- let concrete: t => bool
1616-}
33+module type ATOM = AtomDef.ATOM
174185module IntCmp = Belt.Id.MakeComparable({
196 type t = int
···1212type schematic = int
13131414module Atom = {
1515+ open AtomDef
1516 type t = t
1617 type subst = Map.t<schematic, t>
1818+ type typeTag<_> += Tag: typeTag<t>
1919+ let tag = Tag
2020+ let tagEq = (type a, tag: typeTag<a>): option<eq<t, a>> =>
2121+ switch tag {
2222+ | Tag => Some(Refl)
2323+ | _ => None
2424+ }
1725 let substitute = (term: t, subst: subst) =>
1826 Array.flatMap(term, piece => {
1927 switch piece {
···481489 {React.int(props.idx)}
482490 </span>
483491 }
484484-485485- let makeMeta = (str: string) =>
486486- <span className="rule-binder">
487487- {React.string(str)}
488488- {React.string(".")}
489489- </span>
490492491493 let parenthesise = f =>
492494 [
+1-1
src/StringA.resi
···44 | Schematic({schematic: int, allowed: array<int>})
55type t = array<piece>
6677-module Atom: SExpFunc.ATOM with type t = t
77+module Atom: AtomDef.ATOM with type t = t
88module AtomView: SExpViewFunc.ATOM_VIEW with module Atom := Atom
···11type t = string
22module Atom = {
33+ open AtomDef
34 type t = string
45 type subst = Map.t<int, string>
66+ type typeTag<_> += Tag: typeTag<t>
77+ let tag = Tag
88+ let tagEq = (type a, tag: typeTag<a>): option<eq<t, a>> =>
99+ switch tag {
1010+ | Tag => Some(Refl)
1111+ | _ => None
1212+ }
513 let unify = (a, b, ~gen as _=?) =>
614 if a == b {
715 Seq.once(Map.make())
+1-1
src/Symbolic.resi
···11type t = string
22-module Atom: SExpFunc.ATOM with type t = t
22+module Atom: AtomDef.ATOM with type t = t
33module AtomView: SExpViewFunc.ATOM_VIEW with module Atom := Atom