Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mmottl/pure-fun
Purely functional data structures for OCaml, translated from Chris Okasaki's book "Purely Functional Data Structures"
https://github.com/mmottl/pure-fun
datastructures ocaml purely-functional-data-structures
Last synced: 1 day ago
JSON representation
Purely functional data structures for OCaml, translated from Chris Okasaki's book "Purely Functional Data Structures"
- Host: GitHub
- URL: https://github.com/mmottl/pure-fun
- Owner: mmottl
- License: other
- Created: 2014-07-06T16:31:52.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-10-25T19:49:15.000Z (about 6 years ago)
- Last Synced: 2024-11-08T03:36:30.191Z (3 days ago)
- Topics: datastructures, ocaml, purely-functional-data-structures
- Language: OCaml
- Size: 71.3 KB
- Stars: 142
- Watchers: 10
- Forks: 16
- Open Issues: 1
-
Metadata Files:
- Readme: README-Okasaki.md
- Changelog: CHANGES.md
- License: LICENSE.md
Awesome Lists containing this project
- my-awesome - mmottl/pure-fun - functional-data-structures pushed_at:2018-10 star:0.1k fork:0.0k Purely functional data structures for OCaml, translated from Chris Okasaki's book "Purely Functional Data Structures" (OCaml)
README
This directory contains the Standard ML source code from
```text
Purely Functional Data Structures
Chris Okasaki
Cambridge University Press, 1998
```The code is organized into files according to chapter, from `chp2.sml` to
`chp11.sml`. Each file is self-contained, except for a few miscellaneous
definitions in `base.sml`.The code in the book assumes two non-standard language extensions: support for
lazy evaluation and support for polymorphic recursion. I have modified the
on-line code to work around the lack of polymorphic recursion, but I have made
only minor changes regarding lazy evaluation. IN PARTICULAR, IF YOU COMPILE THE
CODE "AS IS", IT WILL NOT USE LAZY EVALUATION, AND SO WILL NOT ACHIEVE THE
RUNNING TIMES CLAIMED IN THE BOOK.In the book, I assumed that lazy evaluation was supported in the language with a
`$` operator: `$ exp` would create a suspension for the expression `exp`, and
matching that suspension against a pattern of the form `$ pat` would evaluate
and memoize the suspension. In the on-line code, I simulate this with the
following definition in `base.sml`:```sml
datatype 'a susp = $ of 'a
```But, of course, this `$` constructor is not lazy!
There are two further differences related to lazy evaluation. First, the code
in the book assumes that `$` parses with a lower precedence than an ordinary
constructor. Therefore, in the on-line code, I have replaced some occurrences
of `$ exp` with `$ (exp)`. Second, the code in the book assumes the ability to
write lazy functions using a special `fun lazy` syntax. In the on-line code, I
have eliminated dependence on this form.Note that Standard ML of New Jersey now supports lazy evaluation using a
similar, but not quite identical, syntax. Updating the on-line code to use
their syntax requires the following changes:- replace each occurrence of
```sml
val s = $ (exp)
```with
```sml
val lazy s = $ (exp)
```- replace each remaining occurrence of
```sml
... $ (exp) ...
```with
```sml
let val lazy s = $ (exp)
in ... s ... end
```Chris Okasaki
[email protected]