Skip to content

Instantly share code, notes, and snippets.

@matthewhammer
Created January 18, 2016 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewhammer/903b6f909a0a12445e71 to your computer and use it in GitHub Desktop.
Save matthewhammer/903b6f909a0a12445e71 to your computer and use it in GitHub Desktop.
(* Doubly linked list node *)
type 'a dlln = { mutable data : 'a ;
mutable prev : 'a dlln ;
mutable next : 'a dlln }
(* Look ma, a cycle can be initialized without any NULL pointers! *)
let rec singleton : int dlln =
{ data = 0 ;
prev = singleton ;
next = singleton }
;;
@matthewhammer
Copy link
Author

The fields are mutable so that it's morally closer to C. In OCaml, such definitions require no laziness, implicit or explicit. No function abstractions/applications are required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment