···11// type level stuff to enable well-typed coercions
22-type typeTag<_> = ..
22+type atomTag<_> = ..
33type rec eq<_, _> = Refl: eq<'a, 'a>
4455module type ATOM = {
66 type t
77 type subst = Map.t<int, t>
88- let tagEq: typeTag<'a> => option<eq<t, 'a>>
99- let tag: typeTag<t>
88+ type atomTag<_> += Tag: atomTag<t>
99+ let tagEq: atomTag<'a> => option<eq<t, 'a>>
1010 let unify: (t, t, ~gen: ref<int>=?) => Seq.t<subst>
1111 let prettyPrint: (t, ~scope: array<string>) => string
1212 let parse: (string, ~scope: array<string>, ~gen: ref<int>=?) => result<(t, string), string>
···1919 let concrete: t => bool
2020}
21212222-type rec existsValue = ExistsValue(typeTag<'a>, 'a): existsValue
2222+type rec hValue = HValue(atomTag<'a>, 'a): hValue
2323module type COERCIBLE_ATOM = {
2424 include ATOM
2525- let liftForeign: existsValue => option<t>
2626- let unwrap: t => existsValue
2525+ let liftHValue: hValue => option<t>
2626+ let getHValue: t => hValue
2727}
28282929// coercion<t> represents a coercion from some type 'a to t,
3030// along with a function that effectively checks whether its argument is
3131-// an instance of the coerced type. see usage in MakeCoercible.liftForeign
3131+// an instance of the coerced type. see usage in MakeCoercible.liftHValue
3232type rec coercion<_> =
3333- Coercion({tagEq: 'c. typeTag<'c> => option<eq<'a, 'c>>, coerce: 'a => option<'b>}): coercion<'b>
3333+ Coercion({tagEq: 'c. atomTag<'c> => option<eq<'a, 'c>>, coerce: 'a => option<'b>}): coercion<'b>
3434module MakeCoercible = (
3535 Atom: ATOM,
3636 Coercions: {
···3838 },
3939): (COERCIBLE_ATOM with type t = Atom.t) => {
4040 include Atom
4141- let liftForeign = (ExistsValue(tag, val)) =>
4141+ let liftHValue = (HValue(tag, val)) =>
4242 Array.findMap(Coercions.coercions, (Coercion(c)) =>
4343 switch c.tagEq(tag) {
4444 | Some(Refl) => c.coerce(val)
4545 | None => None
4646 }
4747 )
4848- let unwrap = t => ExistsValue(Atom.tag, t)
4848+ let getHValue = t => HValue(Atom.Tag, t)
4949}
50505151exception MatchCombineAtomBoth
···5959 // should not be parsed or otherwise appear organically
6060 | Both(option<Left.t>, option<Right.t>)
6161 // likewise, strictly for Atom <-> Atom coercions
6262- // occurs only when passed from some upper part of the tree
6363- | Foreign(existsValue)
6262+ // occurs only when passed from some sibling part of the tree
6363+ | Foreign(hValue)
6464 include COERCIBLE_ATOM with type t = base
6565 let match: (t, Left.t => 'a, Right.t => 'a) => 'a
6666} => {
···6868 | Left(Left.t)
6969 | Right(Right.t)
7070 | Both(option<Left.t>, option<Right.t>)
7171- | Foreign(existsValue)
7171+ | Foreign(hValue)
7272 type t = base
7373 type subst = Map.t<int, t>
7474 type gen = ref<int>
7575- type typeTag<_> += Tag: typeTag<t>
7676- let tag = Tag
7777- let tagEq = (type a, tag: typeTag<a>): option<eq<t, a>> =>
7575+ type atomTag<_> += Tag: atomTag<t>
7676+ let tagEq = (type a, tag: atomTag<a>): option<eq<t, a>> =>
7877 switch tag {
7978 | Tag => Some(Refl)
8079 | _ => None
8180 }
8282- let liftForeign = v => Some(Foreign(v))
8181+ let liftHValue = v => Some(Foreign(v))
8382 let match = (t, leftBranch: Left.t => 'a, rightBranch: Right.t => 'a): 'a =>
8483 switch t {
8584 | Left(s) => leftBranch(s)
···8786 | Both(_) => throw(MatchCombineAtomBoth)
8887 | Foreign(_) => throw(MatchCombineAtomForeign)
8988 }
9090- let unwrap = t => t->match(Left.unwrap, Right.unwrap)
8989+ let getHValue = t => t->match(Left.getHValue, Right.getHValue)
9190 let parse = (s, ~scope, ~gen: option<gen>=?) => {
9291 Left.parse(s, ~scope, ~gen?)
9392 ->Result.map(((r, rest)) => (Left(r), rest))
···109108 switch t {
110109 | Left(s) => Some(s)
111110 | Both(os, _) => os
112112- | Right(s) => s->Right.unwrap->Left.liftForeign
113113- | Foreign(v) => Left.liftForeign(v)
111111+ | Right(s) => s->Right.getHValue->Left.liftHValue
112112+ | Foreign(v) => Left.liftHValue(v)
114113 }
115114 let coerceToRight = (t): option<Right.t> =>
116115 switch t {
117116 | Right(s) => Some(s)
118117 | Both(_, os) => os
119119- | Left(s) => s->Left.unwrap->Right.liftForeign
120120- | Foreign(v) => Right.liftForeign(v)
118118+ | Left(s) => s->Left.getHValue->Right.liftHValue
119119+ | Foreign(v) => Right.liftHValue(v)
121120 }
122121 let substitute = (s, subst: subst) => {
123122 s->match(
+3-6
src/StringA.res
···1515 open AtomDef
1616 type t = t
1717 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>> =>
1818+ type atomTag<_> += Tag: atomTag<t>
1919+ let tagEq = (type a, tag: atomTag<a>): option<eq<t, a>> =>
2120 switch tag {
2221 | Tag => Some(Refl)
2322 | _ => None
···290289 switch Option.getUnsafe(substs[var - from]) {
291290 | Some(v) => v
292291 | None =>
293293- throw(
294294- SExp.SubstNotCompatible(`index ${Int.toString(var - from)} not of sort string`),
295295- )
292292+ throw(SExp.SubstNotCompatible(`index ${Int.toString(var - from)} not of sort string`))
296293 }
297294 } else {
298295 [Var({idx: var - to})]
+2-3
src/Symbolic.res
···33 open AtomDef
44 type t = string
55 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>> =>
66+ type atomTag<_> += Tag: atomTag<t>
77+ let tagEq = (type a, tag: atomTag<a>): option<eq<t, a>> =>
98 switch tag {
109 | Tag => Some(Refl)
1110 | _ => None