Permalink
Browse files

OCamlの基本構成を追加 refs 11

  • Loading branch information...
1 parent 9382457 commit fcfe4a8f41ff6b4579434c5f316ce414eed82fbe @mzp committed Nov 13, 2010
Showing with 435 additions and 0 deletions.
  1. +11 −0 .gitignore
  2. +47 −0 OMakefile
  3. +45 −0 OMakeroot
  4. +130 −0 base.ml
  5. +191 −0 hList.ml
  6. +2 −0 main.ml
  7. +9 −0 mainTest.ml
View
@@ -0,0 +1,11 @@
+*.cm[ioxa]
+*.cmax
+*.omc
+*.o
+*~
+.omakedb
+.omakedb.lock
+runner
+main
+*.opt
+*.run
View
@@ -0,0 +1,47 @@
+.PHONY: all check install clean
+
+.SUBDIRS:
+
+USE_OCAMLFIND = true
+OCAMLPACKS[] =
+ oUnit
+ extlib
+
+if $(not $(OCAMLFIND_EXISTS))
+ eprintln(This project requires ocamlfind, but is was not found.)
+ eprintln(You need to install ocamlfind and run "omake --configure".)
+ exit 1
+
+NATIVE_ENABLED = $(OCAMLOPT_EXISTS)
+BYTE_ENABLED = $(not $(OCAMLOPT_EXISTS))
+
+OCAMLFLAGS +=
+OCAMLCFLAGS +=
+OCAMLOPTFLAGS +=
+OCAML_LINK_FLAGS +=
+OCAML_BYTE_LINK_FLAGS +=
+OCAML_NATIVE_LINK_FLAGS +=
+
+FILES[] =
+ base
+ hList
+ main
+ mainTest
+
+TEST_FILES[] =
+ mainTest
+
+PROGRAM = main
+TEST_PROGRAM = runner
+OCAML_LIBS +=
+OCAML_CLIBS +=
+OCAML_OTHER_LIBS +=
+OCAML_LIB_FLAGS +=
+
+.DEFAULT : all
+all: $(OCamlProgram $(PROGRAM), $(FILES))
+check : $(OCamlProgram $(TEST_PROGRAM), $(TEST_FILES) $(FILES))
+ ./$(TEST_PROGRAM)
+
+clean:
+ rm -f $(PROGRAM) $(TEST_PROGRAM) *.cm[iox] *.opt *.run *~ *.out *.o
View
@@ -0,0 +1,45 @@
+########################################################################
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this file, to deal in the File without
+# restriction, including without limitation the rights to use,
+# copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the File, and to permit persons to whom the
+# File is furnished to do so, subject to the following condition:
+#
+# THE FILE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE FILE OR
+# THE USE OR OTHER DEALINGS IN THE FILE.
+
+########################################################################
+# The standard OMakeroot file.
+# You will not normally need to modify this file.
+# By default, your changes should be placed in the
+# OMakefile in this directory.
+#
+# If you decide to modify this file, note that it uses exactly
+# the same syntax as the OMakefile.
+#
+
+#
+# Include the standard installed configuration files.
+# Any of these can be deleted if you are not using them,
+# but you probably want to keep the Common file.
+#
+open build/C
+open build/OCaml
+open build/LaTeX
+
+#
+# The command-line variables are defined *after* the
+# standard configuration has been loaded.
+#
+DefineCommandVars()
+
+#
+# Include the OMakefile in this directory.
+#
+.SUBDIRS: .
View
130 base.ml
@@ -0,0 +1,130 @@
+let (@@) f g = f g
+let (+>) f g = g f
+let ($) f g x = f (g x)
+let (!$) = Lazy.force
+external id : 'a -> 'a = "%identity"
+
+let uncurry f a b = f (a,b)
+let curry f (a,b) = f a b
+let flip f a b = f b a
+let const a _ = a
+
+let sure f =
+ function
+ Some x ->
+ Some (f x)
+ | None ->
+ None
+
+let option f x = try Some (f x) with Not_found -> None
+let maybe f x = try `Val (f x) with e -> `Error e
+let tee f x = try ignore @@ f x; x with _ -> x
+
+type ('a,'b) either = Left of 'a | Right of 'b
+
+let failwithf fmt = Printf.kprintf (fun s () -> failwith s) fmt
+
+let assoc x xs = (option @@ List.assoc x) xs
+
+let string_of_list xs =
+ Printf.sprintf "[%s]"
+ @@ String.concat ";" xs
+
+let rec unfold f init =
+ match f init with
+ Some (a, b) -> a :: unfold f b
+ | None -> []
+
+let rec range a b =
+ if a >= b then
+ []
+ else
+ a::range (a+1) b
+
+let rec interperse delim =
+ function
+ [] -> []
+ | [x] -> [x]
+ | x::xs -> x::delim::interperse delim xs
+
+let map_accum_left f init xs =
+ let f (accum,ys) x =
+ let accum',y =
+ f accum x in
+ (accum',y::ys) in
+ let accum,ys =
+ List.fold_left f (init,[]) xs in
+ accum,List.rev ys
+
+let rec map_accum_right f init =
+ function
+ [] ->
+ init,[]
+ | x::xs ->
+ let (accum,ys) =
+ map_accum_right f init xs in
+ let (accum,y) =
+ f accum x in
+ accum,y::ys
+
+let rec filter_map f =
+ function
+ x::xs ->
+ begin match f x with
+ Some y -> y::filter_map f xs
+ | None -> filter_map f xs
+ end
+ | [] ->
+ []
+
+let rec group_by f =
+ function
+ [] ->
+ []
+ | x1::x2::xs when f x1 x2 ->
+ begin match group_by f @@ x2::xs with
+ y::ys ->
+ (x1::y)::ys
+ | _ ->
+ failwith "must not happen"
+ end
+ | x::xs ->
+ [x]::group_by f xs
+
+let index x xs =
+ let rec loop i = function
+ [] ->
+ raise Not_found
+ | y::ys ->
+ if x = y then
+ i
+ else
+ loop (i+1) ys in
+ loop 0 xs
+
+let string_of_char =
+ String.make 1
+
+let hex =
+ Printf.sprintf "0x%x"
+
+let open_out_with path f =
+ let ch =
+ open_out_bin path in
+ maybe f ch
+ +> tee (fun _ -> close_out ch)
+ +> function
+ `Val v -> v
+ | `Error e -> raise e
+
+let open_in_with path f =
+ let ch =
+ open_in_bin path in
+ maybe f ch
+ +> tee (fun _ -> close_in ch)
+ +> function
+ `Val v -> v
+ | `Error e -> raise e
+
+let undefined = Obj.magic 42
+let undef = undefined
Oops, something went wrong.

0 comments on commit fcfe4a8

Please sign in to comment.