Skip to content

c-cube/maki

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
doc
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

maki

Persistent incremental computations, for repeatable tests and benchmarks.

Status: beta

build status

For more details, see the initial design document (obsolete) and the blog post

Examples

Simple memoizing of a recursive function

let fib =
  let rec fib n = Maki.(
      mk1 ~name:"fib" Hash.int Codec.int ~lifetime:Lifetime.one_minute
        ~f:(fun x -> if x <= 1
          then return_ok 1
          else (fib (x-1) >>= fun x1 ->
            fib (x-2) >|= fun x2 -> x1+x2))
        n
    ) in
  fib;;

fib 42 ;;
(* returns [Ok 42] *)

Concatenating file, but memoizing the result as long as they do not change

open Lwt.Infix;;

let concat =
  Maki.(mk2 ~name:"concat" Hash.file_ref Hash.file_ref Codec.string ~lifetime:Lifetime.one_hour
    ~f:(fun f1 f2 ->
      let open E in
      read_file f1 >>= fun content1 ->
      read_file f2 >>= fun content2 ->
      return_ok (content1 ^ content2)))
;;

let x1 = Maki.(File_ref.make "foo1" >>= fun f1 -> File_ref.make "foo2" >>= concat f1);;

(* cached *)
let x2 = Maki.(File_ref.make "foo1" >>= fun f1 -> File_ref.make "foo2" >>= concat f1);;

(* now change contnet of file "foo1", so this should change too *)
let x3 = Maki.(File_ref.make "foo1" >>= fun f1 -> File_ref.make "foo2" >>= concat f1);;

Documentation

See http://c-cube.github.io/maki/

About

[beta] persistent memoization of computations, e.g. for repeatable tests and benchmarks

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published