View Source Guesswork.Ast.Statement protocol (Guesswork v0.5.0)

A Statement is a semantically complete value. It is in no way required to be logically consistent.

Summary

Types

t()

All the types that implement this protocol.

Functions

Takes a statement (ideally non-concrete) and a knowledge base and attempts to find any permutations of bindings for the variables that are true according to the knowledge base and statement.

Attempts to simplify the statement into a less nested operation and returns nil if the statement holds no logical information.

Takes an environment (a mapping of variables to entities) and substitutes the entities into any place the variable is.

Types

@type t() :: term()

All the types that implement this protocol.

Functions

Link to this function

resolve(statement, negated, opts)

View Source

Takes a statement (ideally non-concrete) and a knowledge base and attempts to find any permutations of bindings for the variables that are true according to the knowledge base and statement.

The function also tracks the 'negated' state of the clause it is on, or if the variables it is handling are notted or not.

This function should always return a stream.

The options passed to this function do not have to be used by all implementations, but should always be passed on so that deeper statements can access them.

@spec simplify(t()) :: t() | nil

Attempts to simplify the statement into a less nested operation and returns nil if the statement holds no logical information.

Note that the only requirement for this function is that the input and output statements are logically equivalent, not that the result is the shallowest possible answer (in practice its quite 'greedy' so it is unlikely to produce the 'best' answer, just better).

Link to this function

substitute(statement, env)

View Source
@spec substitute(t(), env()) :: t()

Takes an environment (a mapping of variables to entities) and substitutes the entities into any place the variable is.