Commits

camlspotter committed 49bbf9c

added files

  • Participants

Comments (0)

Files changed (15)

+.*\.cm[a-z]+$
+.*~$
+\.(sp[io]t|annot|o|cm[a-z]+|orig|omc|lock|a|so)$
+\.(byt|opt|run)$
+\.omakedb$
+\.depend$
+CVS/.*
+OCAMLINCLUDES +=
+
+OCAMLFLAGS    += -annot -w Ae
+OCAMLCFLAGS   +=
+OCAMLOPTFLAGS +=
+OCAML_LINK_FLAGS +=
+OCAML_BYTE_LINK_FLAGS +=
+OCAML_NATIVE_LINK_FLAGS +=
+
+# CAMLP4PACKS[]=
+#     sexplib
+# 
+# OCAMLPACKS[]= 
+#     sexplib
+# 
+# OCAMLDEPFLAGS= -syntax camlp4o -package sexplib.syntax
+# OCAMLPPFLAGS= -syntax camlp4o -package sexplib.syntax
+
+# OCamlGeneratedFiles(parser.ml lexer.ml)
+
+LIBFILES[] =
+   base
+   monad
+   option
+   xlist
+   hashSet
+   xformat
+   spot
+
+LIB = spotlib
+
+MyOCamlPackage($(LIB), $(LIBFILES), $(EMPTY), $(EMPTY))
+let failwithf fmt = Printf.kprintf failwith fmt
+
+let memoize f =
+  let cache = Hashtbl.create 101 in
+  fun v -> try Hashtbl.find cache v with Not_found ->
+    let r = f v in
+    Hashtbl.replace cache v r;
+    r
+val failwithf : ('a, unit, string, 'b) format4 -> 'a
+
+val memoize : ('c -> 'd) -> 'c -> 'd
+type 'a t = ('a, unit) Hashtbl.t (* poorman's implementation *)
+let create = Hashtbl.create
+let mem = Hashtbl.mem
+let add t k = if not (mem t k) then Hashtbl.add t k ()
+let remove = Hashtbl.remove
+
+(* Poorman's implementation of polymorphic hash set *)
+type 'a t
+val create : int -> 'a t
+val mem : 'a t -> 'a -> bool
+val add : 'a t -> 'a -> unit
+val remove : 'a t -> 'a -> unit
+
+module type S = sig
+  type 'a t
+  val return : 'a -> 'a t
+  val bind : 'a t -> ('a -> 'b t) -> 'b t
+end
+
+module type T = sig
+  include S
+
+  module Open : sig
+    val bind : 'a t -> ('a -> 'b t) -> 'b t
+    val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
+    val (>>|) : 'a t -> ('a -> 'b) -> 'b t
+    val return : 'a -> 'a t
+  end
+  val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
+  val (>>|) : 'a t -> ('a -> 'b) -> 'b t
+
+  val map : f:('a -> 'b) -> 'a t -> 'b t
+  val ignore : 'a t -> unit t
+  val iter : unit t list -> unit t
+  val seq : 'a t list -> 'a list t
+  val for_ : int -> int -> (int -> unit t) -> unit t
+end
+
+module Make(M:S) : T with type 'a t = 'a M.t = struct
+  include M
+
+  let map ~f t = bind t (fun x -> return (f x))
+
+  module Open = struct
+    let bind = M.bind
+    let (>>=) = M.bind
+    let (>>|) t f = map ~f t
+    let return = return
+  end
+  include Open
+
+  let ignore a = a >>= fun _ -> return ()
+
+  let rec iter = function
+    | [] -> return ()
+    | x::xs -> x >>= fun () -> iter xs
+
+  let rec seq = function
+    | [] -> return []
+    | x::xs -> 
+        x >>= fun x -> 
+        seq xs >>= fun xs ->
+        return (x::xs)
+
+  let rec for_ i to_ f =
+    if i > to_ then return ()
+    else f i >>= fun () -> for_ (i+1) to_ f
+    
+end
+
+(* Minimum monad interfaec *)
+module type S = sig
+  type 'a t
+  val return : 'a -> 'a t
+  val bind : 'a t -> ('a -> 'b t) -> 'b t
+end
+
+module type T = sig
+  type 'a t
+  val return : 'a -> 'a t
+  val bind : 'a t -> ('a -> 'b t) -> 'b t
+  module Open : sig
+    val bind : 'a t -> ('a -> 'b t) -> 'b t
+    val ( >>= ) : 'a t -> ('a -> 'b t) -> 'b t
+    val ( >>| ) : 'a t -> ('a -> 'b) -> 'b t
+    val return : 'a -> 'a t
+  end
+  val ( >>= ) : 'a t -> ('a -> 'b t) -> 'b t
+  val ( >>| ) : 'a t -> ('a -> 'b) -> 'b t
+  val map : f:('a -> 'b) -> 'a t -> 'b t
+  val ignore : 'a t -> unit t
+  val iter : unit t list -> unit t
+  val seq : 'a t list -> 'a list t
+  val for_ : int -> int -> (int -> unit t) -> unit t
+end
+
+module Make(M : S) : T with type 'a t = 'a M.t
+include Monad.Make(struct
+  type 'a t = 'a option
+
+  let return v = Some v
+
+  let bind t f = match t with
+    | Some v -> f v
+    | None -> None
+end)
+include Monad.T with type 'a t = 'a option
+module Base = Base
+module Monad = Monad
+module Option = Option
+module List = struct
+  include List
+  include Xlist
+end
+module Format = struct
+  include Format
+  include Xformat
+end
+open Format
+
+type t = formatter
+
+let rec list sep f ppf = function
+  | [] -> ()
+  | [x] -> f ppf x
+  | x::xs ->
+    fprintf ppf "%a%t%a"
+      f x
+      sep
+      (list sep f) xs
+open Format
+
+type t = formatter
+val list : (t -> unit) -> (t -> 'a -> unit) -> t -> 'a list -> unit
+open List
+
+let iteri f l =
+  let rec iter n = function
+    | [] -> ()
+    | x::xs -> f n x; iter (n+1) xs
+  in
+  iter 0 l
+
+let mapi f l = 
+  let rec map n = function
+    | [] -> []
+    | x::xs -> f n x :: map (n+1) xs
+  in
+  map 0 l
+
+val iteri : (int -> 'a -> 'b) -> 'a list -> unit
+val mapi : (int -> 'a -> 'b) -> 'a list -> 'b list