[doc] Clarify unification semantics #160
Labels
No labels
A-build
A-cli
A-core
A-design
A-edn
A-ffi
A-query
A-sdk
A-sdk-android
A-sdk-ios
A-sync
A-transact
A-views
A-vocab
P-Android
P-desktop
P-iOS
bug
correctness
dependencies
dev-ergonomics
discussion
documentation
duplicate
enhancement
enquiry
good first bug
good first issue
help wanted
hygiene
in progress
invalid
question
ready
size
speed
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: greg/mentat#160
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Query variables unify. This occurs at two levels: down in SQLite (which does all the work of a query engine, of course), and also deliberately within Mentat, as we decide how to construct SQL queries that implement Datalog semantics.
Datomic doesn't explicitly document its unification behavior. Clojure itself offers several kinds of equality comparison:
identical?
, which tests whether two objects are the same. Primitives (with the exception of some boxed JVM fixnums) are almost neveridentical?
.=
, which compares collections type-agnostically, and otherwise is the usual value-space equality comparison you might expect.==
, which is numeric equality, and works across numeric types.The following REPL session should be illuminating:
Without experimenting, I'd bet that Datomic unifies with
=
, and thus these two queries are identical:Notably this means that keywords don't unify with strings, and doubles don't unify with longs. That makes sense for Mentat, too:
TypedValue::Keyword(":foo/bar")
shouldn't unify withTypedValue::String(":foo/bar")
despite having the same database representation, and arguablyTypedValue::Double(5.0)
andTypedValue::Long(5)
shouldn't unify either.We should do the following:
Experiment with Datomic and DataScript to define their behavior.
Decide on and document ours. A few good illustrations would be
Whether these match long-valued, double-valued, or both kinds of attributes of
?x
is down to the chosen unification semantics and also the representation of literal values in queries and in inputs.Implement
=
and==
to allow for queries to be written that implement numeric or exact equality without being phrased as patterns.Continue to correctly implement type tag matching clauses in order to follow our defined unification behavior.