Skip to content

Commit

Permalink
Rename elem to witness in Slots
Browse files Browse the repository at this point in the history
  • Loading branch information
wokalski committed Jan 17, 2019
1 parent 77bbe63 commit c80f053
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
8 changes: 4 additions & 4 deletions core/lib/Hooks.re
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module State = {
let (stateContainer, nextSlots) =
Slots.use(
~default=() => make(initialState),
~toElem=wrapAsHook,
~toWitness=wrapAsHook,
hooks.slots,
);

Expand Down Expand Up @@ -103,7 +103,7 @@ module Reducer = {
let (stateContainer, nextSlots) =
Slots.use(
~default=() => make(initialState),
~toElem=wrapAsHook,
~toWitness=wrapAsHook,
hooks.slots,
);

Expand All @@ -126,7 +126,7 @@ module Ref = {
let (internalRef, nextSlots) =
Slots.use(
~default=() => ref(initialState),
~toElem=wrapAsHook,
~toWitness=wrapAsHook,
hooks.slots,
);

Expand Down Expand Up @@ -222,7 +222,7 @@ module Effect = {
cleanupHandler: None,
previousCondition: condition,
},
~toElem=wrapAsHook,
~toWitness=wrapAsHook,
hooks.slots,
);

Expand Down
2 changes: 1 addition & 1 deletion core/lib/Hooks.rei
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type hook('a) = ..;

module Slots: Slots.S with type elem('a) = hook('a);
module Slots: Slots.S with type witness('a) = hook('a);

type t('a, 'b) = {
slots: Slots.t('a, 'b),
Expand Down
28 changes: 14 additions & 14 deletions core/lib/Slots.re
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
module type Elem = {type t('a);};
module type Witness = {type t('a);};

module type S = {
type elem('a);
type opaqueElement =
| Any(elem('a)): opaqueElement;
type witness('a);
type opaqueValue =
| Any(witness('a)): opaqueValue;
type t('slot, 'nextSlots);
type empty = t(unit, unit);

let create: unit => t('slot, 'nextSlots);
let use:
(
~default: unit => 'slot,
~toElem: 'slot => elem('slot),
~toWitness: 'slot => witness('slot),
t('slot, t('slot2, 'nextSlots))
) =>
('slot, t('slot2, 'nextSlots));

let fold:
((opaqueElement, 'acc) => 'acc, 'acc, t('slots, 'nextSlots)) => 'acc;
((opaqueValue, 'acc) => 'acc, 'acc, t('slots, 'nextSlots)) => 'acc;
};

module Make = (Elem: Elem) => {
type elem('a) = Elem.t('a);
module Make = (Witness: Witness) => {
type witness('a) = Witness.t('a);

type opaqueElement =
| Any(Elem.t('a)): opaqueElement;
type opaqueValue =
| Any(Witness.t('a)): opaqueValue;

type slotInternal('slot, 'nextSlots) = {
value: 'slot,
fold: 'acc. ((opaqueElement, 'acc) => 'acc, 'acc) => 'acc,
fold: 'acc. ((opaqueValue, 'acc) => 'acc, 'acc) => 'acc,
next: 'nextSlots,
};

Expand All @@ -41,11 +41,11 @@ module Make = (Elem: Elem) => {
let use:
(
~default: unit => 'slot,
~toElem: 'slot => elem('slot),
~toWitness: 'slot => witness('slot),
t('slot, t('slot2, 'nextSlots))
) =>
('slot, t('slot2, 'nextSlots)) =
(~default, ~toElem, slots) =>
(~default, ~toWitness, slots) =>
switch (slots^) {
| None =>
let nextSlots = create();
Expand All @@ -55,7 +55,7 @@ module Make = (Elem: Elem) => {
value,
next: nextSlots,
fold: (f, initialValue) => {
let acc = f(Any(toElem(value)), initialValue);
let acc = f(Any(toWitness(value)), initialValue);
switch (nextSlots^) {
| Some({fold}) => fold(f, acc)
| None => acc
Expand Down
16 changes: 8 additions & 8 deletions core/lib/Slots.rei
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
module type Elem = {type t('a);};
module type Witness = {type t('a);};

module type S = {
type elem('a);
type opaqueElement =
| Any(elem('a)): opaqueElement;
type witness('a);
type opaqueValue =
| Any(witness('a)): opaqueValue;
type t('slot, 'nextSlots);
type empty = t(unit, unit);

let create: unit => t('slot, 'nextSlots);
let use:
(
~default: unit => 'slot,
~toElem: 'slot => elem('slot),
~toWitness: 'slot => witness('slot),
t('slot, t('slot2, 'nextSlots))
) =>
('slot, t('slot2, 'nextSlots));

let fold:
((opaqueElement, 'acc) => 'acc, 'acc, t('slots, 'nextSlots)) => 'acc;
((opaqueValue, 'acc) => 'acc, 'acc, t('slots, 'nextSlots)) => 'acc;
};

module Make: (Elem: Elem) => S with type elem('a) = Elem.t('a);
module Make: (Witness: Witness) => S with type witness('a) = Witness.t('a);

include S with type elem('a) = 'a;
include S with type witness('a) = 'a;

0 comments on commit c80f053

Please sign in to comment.