Skip to content

Commit

Permalink
[refactoring] extract nothing/
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Sep 4, 2024
1 parent 0bc88d3 commit 2f4671d
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/belief-system/beliefSystemMerge.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Belief } from "../belief/index.js"
import { isNothing, nothing, type Nothing } from "../cell/index.js"
import { implies, merge, type MergeConflict } from "../merge/index.js"
import { isNothing, nothing, type Nothing } from "../nothing/index.js"
import type { Reasons } from "../reason/index.js"
import { setIsSubsetOf } from "../utils/set/index.js"
import { BeliefSystem } from "./BeliefSystem.js"
Expand Down
2 changes: 1 addition & 1 deletion src/cell/Cell.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nothing, type Nothing } from "../nothing/index.js"
import type { Propagator } from "../propagator/index.js"
import { nothing, type Nothing } from "./Nothing.js"

export type Cell<T> = {
"@type": "Cell"
Expand Down
1 change: 0 additions & 1 deletion src/cell/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./addPropagator.js"
export * from "./Cell.js"
export * from "./Nothing.js"
export * from "./put.js"
2 changes: 1 addition & 1 deletion src/merge/merge-nothing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isNothing } from "../cell/index.js"
import { defineHandler } from "../generic/index.js"
import { isNothing } from "../nothing/index.js"
import { merge } from "./merge.js"

function isAnything(x: any): true {
Expand Down
41 changes: 22 additions & 19 deletions src/merge/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ import { defineGeneric } from "../generic/index.js"
//
// The contract of the generic function merge is that it takes two
// arguments the currently known information and the new information
// being supplied, and returns the new aggregate information. If the
// information being supplied is redundant, the merge function should
// return exactly (by `===`) the original information, so that the
// cell can know that the news was redundant and not alert its
// neighbors. If the new information contradicts the old information,
// merge should return a distinguished value indicating the
// contradiction, so that the cell can signal an error. For symmetry
// and future use, if the new information strictly supersedes the old
// (i.e., if the old information would be redundant given the new, but
// the new is not redundant given the old) merge is expected to return
// exactly (by `===`) the new information.

// # `merge` is not entirely symmetric
// being supplied, and returns the new aggregate information.
//
// - If the information being supplied is redundant, the merge
// function should return exactly (by `===`) the original
// information, so that (when calling the `put` function) the cell
// can know that the news was redundant and not alert its neighbors.
//
// - If the new information contradicts the old information, merge
// should return a distinguished value indicating the contradiction,
// so that the cell can signal an error. For symmetry and future
// use.
//
// - If the new information strictly supersedes the old (i.e., if the
// old information would be redundant given the new, but the new is
// not redundant given the old) merge is expected to return exactly
// (by `===`) the new information.
//
// If the first and second arguments represent equivalent information
// but are not equal (by `===`), merge must return the first rather
// than the second. This is a consequence of the asymmetry in the
// cells’ treatment of their existing content versus incoming
// content. Having merge return the wrong one could lead to spurious
// infinite loops.
// - If the first and second arguments represent equivalent
// information but are not equal (by `===`), merge must return the
// first rather than the second. This is a consequence of the
// asymmetry in the cells’ treatment of their existing content
// versus incoming content. Having merge return the wrong one could
// lead to spurious infinite loops.

export const merge = defineGeneric()

Expand Down
2 changes: 1 addition & 1 deletion src/monad/belief-monad.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Belief, isBelief } from "../belief/index.js"
import { isNothing, nothing } from "../cell/Nothing.js"
import { defineHandler } from "../generic/index.js"
import { isNothing, nothing } from "../nothing/index.js"
import { isFunction } from "../utils/isFunction.js"
import { setUnion } from "../utils/set/index.js"
import { bind, flatten, fmap } from "./monad.js"
Expand Down
2 changes: 1 addition & 1 deletion src/monad/nothing-monad.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isNothing, nothing } from "../cell/Nothing.js"
import { defineHandler } from "../generic/index.js"
import { isNothing, nothing } from "../nothing/index.js"
import { isFunction } from "../utils/isFunction.js"
import { flatten, fmap } from "./monad.js"

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/nothing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Nothing.js"

0 comments on commit 2f4671d

Please sign in to comment.