1. camlspotter
  2. planck

Commits

camlspotter  committed 04bf046

use spotlib

  • Participants
  • Parent commits 78c39fc
  • Branches default

Comments (0)

Files changed (9)

File OMakefile

View file
 
 OCAMLPACKS[]= 
     sexplib
+    spotlib
 
 OCAMLDEPFLAGS= -syntax camlp4o -package sexplib.syntax
 OCAMLPPFLAGS= -syntax camlp4o -package sexplib.syntax
 # OCamlGeneratedFiles(parser.ml lexer.ml)
 
 LIBFILES[] =
-   utils
    position
    result
    stream

File pcore.ml

View file
-open Utils
+open Spotlib.Spot
 
 type ('a, 'pos) generator = ('a, 'pos) Stream.generator
 
   module Str : Stream.S
   exception Error of Str.pos * string
   module Result : Result.S with type error = Str.pos * string
-  include Utils.Monad.T with type 'a t = Str.t -> ('a * Str.t) Result.t
+  include Monad.T with type 'a t = Str.t -> ('a * Str.t) Result.t
   val take : Str.elem t
   val pos : 'a t -> ('a * Str.pos) t
   val error : string -> 'a t

File pcore.mli

View file
   exception Error of Str.pos * string
   module Result : Result.S with type error = Str.pos * string
   
-  include Utils.Monad.T with type 'a t = Str.t -> ('a * Str.t) Result.t
+  include Spotlib.Spot.Monad.T with type 'a t = Str.t -> ('a * Str.t) Result.t
 
   val take : Str.elem t
   val pos : 'a t -> ('a * Str.pos) t

File plang.ml

View file
-open Utils
+open Spotlib.Spot
 
 module type P = sig
   include Pcore.S with type Str.elem = Sbuffer.elem

File result.ml

View file
-open Utils
+open Spotlib.Spot
 
 module type S = sig
   type error

File result.mli

View file
 (* Result monad *)
 
-open Utils
+open Spotlib.Spot
 
 module type S = sig
   type error

File sbuffer.ml

View file
-open Utils
+open Spotlib.Spot
 open Stream
 
 (* string stream. Not of char. *)

File stream.ml

View file
-open Utils
+open Spotlib.Spot
 
 module type S0 = sig
   type t (** type of the stream *)

File utils.ml

-module Monad = struct
-  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
-end
-
-module Option = 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
-
-  let map ~f = function
-    | Some v -> Some (f v)
-    | None -> None
-end)
-
-module HashSet : sig
-  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
-end = struct
-  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
-end
-
-module Format = struct
-  include Format
-
-  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
-end
-
-let failwithf fmt = Printf.kprintf failwith fmt
-
-module List = struct
-  include 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
-end