Module Std.Blang


module Blang: Blang


Blang provides infrastructure for writing simple boolean DSLs. All expressions in a Blang language evaluate to a bool. To get a concrete language, you need to parameterize the language with some value type, where values can also be evaluated to true or false.

The syntax is almost exactly the obvious s-expression syntax, except that:

1. Base elements do not need to be marked explicitly. Thus, if your value language had two elements, "true" and "false", then you could write the following Blang s-expressions:

true (if true true false)

and so on. Note that this can get in the way of using the blang keywords in your value language.

2. the argument lists for And and Or should not be wrapped in parens. i.e., you can write:

(and true (or true false false) (and true) (and) (not (or)))

type 'a t =
| And of 'a t list
| Or of 'a t list
| Not of 'a t
| If of 'a t * 'a t * 'a t
| Base of 'a

include Sexpable.S1
Note that the sexps are not directly inferred from the type above -- there are lots of fancy shortcuts. Also, the sexps for 'a must not look anything like blang sexps. Otherwise t_of_sexp will fail.
include Binable.S1
val values : 'a t -> 'a list
values t forms the list containing every v for which Base v is a subexpression of t
val true_ : 'a t
val false_ : 'a t
include Monad
Blang.t's monad works as follows:
val eval : ('a -> bool) -> 'a t -> bool