A high-level API that brings together the Logic.* submodules into a cohesive module.
Work with integers, floats, booleans, characters, and strings out of the box. There's also the possibility to bring in your own custom types.
Create an integer value.
Create a floating-point value.
Create a boolean value.
Create a character value.
Create a string value.
Create a value out of your custom type.
Convert a value to a constant, if possible.
toConstant (int 5) == Just (Int 5)
toConstant null == NothingThe empty list value.
Create a dotted pair of any two values.
Create a proper list of zero or more values.
list [] == null
list [ int 1 ] == cons (int 1) null
list [ int 1, bool True ] == cons (int 1) (cons (bool True) null)
list [ int 1, bool True, char 'a' ] == cons (int 1) (cons (bool True) (cons (char 'a') null))Create an improper list of two or more values.
dottedList (int 1) [] (bool True) == cons (int 1) (bool True)
dottedList (int 1) [ bool True ] (char 'a') == cons (int 1) (cons (bool True) (char 'a'))Get the first value from a dotted pair, if possible.
car (cons x y) == Just x
car null == Nothing
car (string "(cons x y)") == NothingGet the second value from a dotted pair, if possible.
cdr (cons x y) == Just y
cdr null == Nothing
cdr (string "(cons x y)") == NothingGet the first and second value from a dotted pair, if possible.
uncons (cons x y) == Just ( x, y )
uncons null == Nothing
uncons (string "(cons x y)") == NothingImbue the underlying Goal type with a richer set of constants.
See Logic.Goal for more details.
A goal that succeeds.
A goal that fails.
A goal that succeeds an unbounded number of times.
A goal that neither succeeds nor fails.
Try to unify two values. It succeeds if unification is possible, and fails otherwise.
The disjunction of two goals. It succeeds if and only if either of the goals succeed.
The disjunction of zero or more goals. It succeeds if and only if there is at least one goal that succeeds.
The conjunction of two goals. It succeeds if and only if both goals succeed.
The conjunction of zero or more goals. It succeeds if and only if all the goals succeed.
The disjunction of conjunctions.
See Logic.Goal.conde for more details.
Useful for defining recursive goals.
Create a lexically-scoped logic variable.
fresh
(\fruit ->
equals (Const "plum") fruit
)Create two lexicaly-scoped logic variables.
Create three lexicaly-scoped logic variables.
Create four lexicaly-scoped logic variables.
Create five lexicaly-scoped logic variables.
Create six lexicaly-scoped logic variables.
Create seven lexicaly-scoped logic variables.
Create eight lexicaly-scoped logic variables.
See Logic.Goal for more details on these operators.
See Logic.Goal for more details on these runners.
Convert to a representation that's useful for debugging and testing.
toString [ int 1, float 3.14, bool True, bool False, char 'c', string "apple", custom "banana" ] == "(1 3.14 #t #f c apple banana)"
toString [ null, cons (int 1) (int 2), list [ int 1 ], list [ int 1, bool True ] ] == "(() (1 . 2) (1) (1 #t))"
toString [ dottedList (int 1) [ bool True ] (char 'a') ] == "((1 #t . a))"N.B. For convenience, it assumes your custom type is String. If your custom type
is something else you can use customToString instead.
Used by customToString to determine how to represent your custom type.
With the Default constructor you get to use the default representation for the constants while
providing a function to represent your custom type.
The default representation for the constants is as follows:
toString [ int 1 ] == "(1)"
toString [ float 3.14 ] == "(3.14)"
toString [ bool True ] == "(#t)"
toString [ bool False ] == "(#f)"
toString [ char 'a' ] == "(a)"
toString [ string "xyz" ] == "(xyz)"If you want to change the default representation for the constants you can do that by using
the Alternative constructor.
Convert to a representation that's useful for debugging and testing.
Additionally, you get to determine how to represent your custom type.
A rich default set of values that can be associated with (logic) variables.