package fix

  1. Overview
  2. Docs
Facilities for memoization and fixed points

Install

Dune Dependency

Authors

Maintainers

Sources

archive.tar.gz
md5=991ff031666c662eaab638d2e0f4ac1d
sha512=01c45a1d90b02ec0939e968b185a6a373ac6117e2287b9a26d3db9d71e9569d086cea50da60710fcab5c2ed9d3b4c72b76839c0651e436f1fb39c77dc7c04b5e

Description

Published: 01 Feb 2020

README

Fix: memoization and fixed points made easy

fix is an OCaml library that helps with various constructions that involve memoization and recursion.

Installation

Type opam install fix.

Overview

At the top of an OCaml module, declare open Fix. This gives you access to the following submodules:

  • Gensym offers a simple facility for generating fresh integer identifiers.

  • Memoize offers a number of combinators that help construct possibly recursive memoizing functions, that is, functions that lazily record their input/output graph, so as to avoid repeated computation.

  • Tabulate offers facilities for tabulating a function, that is, eagerly evaluating this function at every point in its domain, so as to obtain an equivalent function that can be queried in constant time.

  • Numbering offers a facility for assigning a unique number to each value in a certain finite set and translating (both ways) between values and their numbers.

  • GraphNumbering offers a facility for discovering and numbering the reachable vertices in a finite directed graph.

  • HashCons offers support for setting up a hash-consed data type, that is, a data type whose values carry unique integer identifiers.

  • Fix offers support for computing the least solution of a set of monotone equations, as described in the unpublished paper Lazy Least Fixed Points in ML. In other words, it allows defining a recursive function of type variable -> property, where cyclic dependencies between variables are allowed, and properties must be equipped with a partial order. The function thus obtained performs the fixed point computation on demand, in an incremental manner, and is memoizing.

  • Prop defines a few common partial orders, including Prop.Boolean, Prop.Option, Prop.Set.

  • Glue contains glue code that helps build various implementations of association maps.

The signatures that appear in the above files, such as MEMOIZER, TABULATOR, SOLVER, and so on, are defined here.

Demos

A few demos are provided:

  • brz sets up a hash-consed representation of regular expressions and shows how to convert a regular expression to a deterministic finite-state automaton by Brzozowski's method. This demo exploits almost all of the submodules listed above, and is accompanied with a commentary.

  • cyk presents a CYK-style parsing algorithm as an instance of Fix.

  • cfg uses Fix to perform certain static analyses of a context-free grammar; this includes computing nullability information and FIRST sets.

  • fib defines Fibonacci's function in several different ways using the fixed-point combinators offered by Memoize and Fix.

  • hco sets up simple-minded hash-consed trees using HashCons.

Dependencies (2)

  1. dune >= "1.3"
  2. ocaml >= "4.03" & < "5.0"

Dev Dependencies

None

Used by (10)

  1. feat < "20211224"
  2. karamel
  3. kremlin < "transition"
  4. mezzo
  5. ocamlformat >= "0.14.0" & < "0.25.1"
  6. ocamlformat-lib
  7. ocamlformat-mlx-lib
  8. ocamlformat-rpc < "0.21.0"
  9. reason >= "3.6.0"
  10. refl

Conflicts

None

OCaml

Innovation. Community. Security.