package bindlib
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=49400a6c8a9089b21adaaf7741319596
sha512=ef0353a1b34c9790bd46e964773540a6642253d9eb6a6d57a2e80c54ac9de730d4b79540603fd6aea8ed321455b5a13d6ec8bd380c32e7bb17fe0e400360e90d
doc/CHANGELOG.html
Bindlib 6.0.0
Breaking changes:
- Major change of semantics that impacts variable renaming (and printing). The new semantics is explained in the documentation (see the
.mlifile), and a guide for porting code is provided below.
Other changes:
- Compilation using Dune.
- Generation of the
bindlib.opamfile using Dune. - Require at least OCaml 4.07.0 (not strictly necessary, but solves CI issues with the installation of Dune on older versions).
- Cleaning up of the documentation in the code (
.mlfile). - Polishing of the interface documentation (
.mlifile). - Add the
unbind2_infunction (similar tounbind2but with a context). - Add the
unmbind2_infunction (similar tounmbind2but with a context). - Add the
free_varsfunction to construct a context containing all the free variables in a boxed value. - Add the
reserve_namefunction to reserve a variable name in a context. - Add a functor
Ctxtthat can be used to define a custom variable renaming policy, given a type of contexts and a few configurations.
This releases breaks your printing code: here is how to fix it
Note: only the printing code is broken, all the rest is fine.
To understand the problem, recall that variable substitutions does not perform any bound variable renaming in Bindlib. What used to be the case, was that the bound variable names were appropriately updated upon term construction. A term that was freshly constructed was hence guaranteed to be safe for printing, and thus it was advised to do a "cleanup" term traversal before printing (this was done by composing a user-defined boxing function of type t -> t Bindlib.box, and the build-in Bindlib.unbox function).
For example, with a type of the terms of the λ-calculus, that would be done as follows, using the appropriate smart constructors.
type term =
| Var of term Bindlib.var
| Abs of (term, term) Bindlib.binder
| App of term * term
let var = Bindlib.box_var
let abs = Bindlib.box_apply (fun b -> Abs(b))
let app = Bindlib.box_apply2 (fun t u -> App(t,u))
let rec box_term: term -> term Bindlib.box = fun t ->
match t with
| Var(x) -> var x
| Abs(b) -> abs (Bindlib.box_binder box_term b)
| App(t,u) -> app (box_term t) (box_term u)
(* DOES NOT GUARANTEE THAT THE OUTPUT TERM IS SAFE FOR PRINTING ANYMORE. *)
let cleanup: term -> term = fun t ->
Bindlib.unbox (box_term t)
(* Naive printing function assuming correct names. *)
let rec to_string: term -> string = fun t ->
match t with
| Var(x) -> Bindlib.name_of x
| Abs(b) -> let (x,t) = Bindlib.unbind b in
"λ" ^ Bindlib.name_of x ^ "." ^ to_string t
| App(t,u) -> "(" ^ to_string t ^ ") " ^ to_string u
(* BROKEN PRINTING FUNCTION AS OF BINDLIB VERSION 6.0.0. *)
let to_string t = to_string (cleanup t)What do we do now?
In this new version of Bindlib, a function that prints or displays a term must rely on a context (of type Bindlib.ctxt) for free variables. All renaming is performed when introducing fresh variables to substitute binders using special functions like Bindlib.new_var_in or Bindlib.unbind_in, which take care of picking a fresh name and maintaining the context.
Going back to the λ-calculus, the printing function must become the following.
(** [to_string_in ctxt t] is safe for printing assuming that [ctxt] is a valid
context for [t] (i.e., it contains all of its free variables). *)
let rec to_string_in : ctxt -> term -> string = fun ctxt t ->
match t with
| Var(x) -> Bindlib.name_of x
| Abs(b) -> let (x,t,ctxt) = Bindlib.unbind_in ctxt b in
"λ" ^ Bindlib.name_of x ^ "." ^ to_string_in ctxt t
| App(t,u) -> "(" ^ to_string_in ctxt t ^ ") " ^ to_string_in ctxt u
(** [to_string t] is always safe for printing. *)
let to_string : term -> string = fun t ->
to_string_in (Bindlib.free_vars (box_term t)) tIn some situations where a form of context is required anyway (e.g., for doing type-checking), it might make sense to maintain a Bindlib context to avoid the cost of a call to box_term at printing time. However, this also means that a small cost for maintaining names is payed early on.
Bindlib 5.0.1 (21/08/2018)
Bug fixes:
- Partially-applied
new_varfunction could lead to variables with the same unique identifier (fixed by an η-expansion). - The case where
unmbind2was called with multiple binders with different arities was not handled, which could lead to problems (fixed by raisingInvalid_argument "Arity missmatch in unmbind2"on an arity mismatch). - The
eq_mbinderfunction also suffered from the same problem asunmbind2(fixed by returningfalseon an arity mismatch).
Other changes:
- Documentation update for
unmbind2andeq_mbinder.
Bindlib 5.0.0 (27/05/2018)
Breaking changes:
- Rename type
'a bindboxinto'a box. - Variance annotations removed on the
('a,'b) bindertype. - Remove the
bindfunction (usebind_varinstead). - Remove the
mbindfunction (usebind_mvarinstead). - Remove the (unsafe)
binder_compose_leftfunction. - Rename the (less unsafe)
binder_compose_rightintobinder_compose. - Remove the (unsafe)
binder_from_funfunction (replaced byraw_binder). - Remove the (unsafe)
mbinder_from_funfunction (replaced byraw_mbinder). - Remove the
bind_infunction. - Rename the
box_of_varfunction intobox_var. - Change the order of arguments of
copy_varto matchnew_var. - Remove the first argument of
eq_binder(not necessary anymore). - Remove the first argument of
eq_mbinder(not necessary anymore). - Remove the
fixpointfunction (too specific, and expressible). - Remove the
is_substitutedfunction (semantics not clear). - Remove the
prefix_offunction (abstraction-breaking). - Remove the
suffix_offunction (abstraction-breaking). - Remove the first argument of
unbind(not necessary anymore). - Remove the first argument of
unbind2(not necessary anymore). - Remove the first argument of
unbind_in(not necessary anymore). - Remove the first argument of
unmbind(not necessary anymore). - Remove the first argument of
unmbind2function (not necessary anymore). - Remove the first argument of
unmbind_in(not necessary anymore). - Remove the
vbindfunction (usebind_varinstead).
Other changes:
- Major improvement of the documentation, and description of the library in a paper.
- Add the
box_binderfunction (useful helper). - Add the
box_mbinderfunction (useful helper). - Add the (unsafe)
mbinder_composefunction. - Add the (unsafe)
raw_binderfunction to construct binders "manually". - Add the (unsafe)
raw_mbinderfunction (similar toraw_binder). - Add the
uids_offunction (similar touid_of).
Bindlib 4.0.5 (24/01/2018)
Breaking changes:
- Remove the
free_offunction (users must now remember the injection).
Other changes:
- Add the (unsafe)
uid_offunction that can be used to obtain the unique identifier associated to a variable (useful for hashing). - Add the
unbind2function that destructs two binders at once with the same (fresh) variable. - Add the
eq_binderfunction for testing equality of binders given an equality function for the bodies. - Add the
unmbind2function (similar tounbind2). - Add the
eq_binderfunction (similar toeq_binder). - Add the
is_substitutedfunction.
Bindlib 4.0.4 (21/08/2017)
Breaking changes:
- Rename
fintolift_boxin the signature of theLiftfunctor. - Rename
fintolift_boxin the signature of theLift2functor. - Remove the (unsafe)
apply_in_boxfunction. - Remove the (useless)
list_varsfunction.
Other changes:
- Require at least OCaml 3.12.1.
- Major cleaning up and documentation effort.
- Move from
darcstogit. - Add the
mbinder_from_funfunction (similar tobinder_from_fun). - Add the
mbinder_occursfunction (similar tobinder_occur). - Add the
mbinder_rankfunction (similar tobinder_rank). - Add the
suffix_offunction to query the suffix of a variable name.
Bindlib 4.0.3
Breaking changes:
- Rename the
'a variabletype into'a var. - Rename the
'a mvariabletype into'a mvar. - Rename the
compare_variablesfunction intocompare_vars. - Rename the
eq_variablesfunction intoeq_vars. - Rename the
contexttype intoctxt. - Rename the
list_variablesfunction intolist_vars.
Other changes:
- Add the
prefix_offunction to query the prefix of a variable name. - Add the
unmbindfunction which destructs a multiple binder (like theunbindfunction for binders). - Add the
unbind_inandunmbind_infunctions, which are similar tounbindandunmbindbut work with a context. - Remove the
Bindlib_utilandPtmapmodules (not meant to be exposed).
Bindlib 4.0.2
Breaking changes:
- Remove the second (
int) argument of the unsafebinder_from_funfunction, which also has now a different semantics.
Other changes:
- Document the
binder_from_funfunction (unsafe). - Add the
box_apply4function.
Bindlib 4.0
Major cleanup/rewriting of the library by Rodolphe Lepigre. First version distributed via Opam.
Earlier versions
All earlier versions of Bindlib were developed by Christophe Raffalli. A version for Haskell was even available at some point.