[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MirageOS-devel] Irmin RW store questions



I’d like to use Irmin RW store to implement a simple timestamp based last-writer-wins register. While the type of Irmin.AO_MAKER = functor (K : Irmin.Hash.S) (V : Tc.S0) -> … is understandable, the type of Irmin.RW_MAKER = (K : Irmin.Hum.S) (V : Irmin.Hash.S) -> … is not intuitive. Why is the type of K and V not the same as in AO_MAKER? Why should the type of value be a Hash.S?

I also witness surprising behaviour for any non-string keys with Git memory backend. See the code below. Are there any restrictions with the use of RW stores?

(* Build with
 * ocamlfind ocamlc -linkpkg -package irmin.git,irmin.unix,git -o rw_test rw_test.ml
 *)

let (>>=) = Lwt.bind

module Git = Irmin_git.RW(Git.Memory)

module HumInt = struct
  include Tc.Int
  let of_hum s = 
    (* Following line prints “master" *)
    print_string @@ s^"\n";
    int_of_string s
  let to_hum = string_of_int
end

module HumString = struct
  include Tc.String
  let of_hum s = s 
  let to_hum s = s 
end

(*****************************************************************************)

(* Following Fails *)
module Hum = HumInt
let key = 0 


(* Following works *)
(*
module Hum = HumString
let key = "0"
*)

(*****************************************************************************)

module S = Git(Hum)(Irmin.Hash.SHA1)
module SHA1 = Irmin.Hash.SHA1

let conf = Irmin_git.config ()
let task = Irmin_unix.task

let main =
  S.create conf task
  >>= fun store ->
      S.update (store "update") key 
      (SHA1.of_hum "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12")
  >>= fun _ -> S.read_exn (store "read") key 
  >>= fun res ->
        SHA1.to_hum res |> print_string;
        Lwt.return ()

let () = Lwt_main.run main

Thanks
KC
_______________________________________________
MirageOS-devel mailing list
MirageOS-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.