Skip to content

Instantly share code, notes, and snippets.

camlspotter

Block or report user

Report or block camlspotter

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:9347554
let () =
prerr_endline @@ GMain.Main.init ();
let window = GWindow.window ~title: "liv" ~allow_shrink: true ~allow_grow: true () in
window#show ();
window#event#add [`SCROLL];
ignore @@ window#event#connect#scroll ~callback:(fun ev ->
Printf.eprintf "at +%.0f+%.0f %s\n%!"
(GdkEvent.Scroll.x ev)
(GdkEvent.Scroll.y ev)
View gist:e9e8bd808c7c98e7579e
(* OCaml version
compile with:
ocamlopt str.cmxa -o classifyDigits classifyDigits.ml
*)
(*
// This F# dojo is directly inspired by the
// Digit Recognizer competition from Kaggle.com:
// http://www.kaggle.com/c/digit-recognizer
// The datasets below are simply shorter versions of
@camlspotter
camlspotter / gist:96b01590db525344d92a
Created Sep 23, 2014
Message passing by record labels, variants, GADTs and polymorphic variants.
View gist:96b01590db525344d92a
open Printf
module ByMonomorphicRecord = struct
(* Interface by a monomorphic record *)
type point = {
get : unit -> int;
set : int -> unit;
print : unit -> unit;
}
View Object Emulation
(*
OCaml translation of the ideas explained in http://fumieval.hatenablog.com/entry/2014/09/22/144401
To emulate the higher kinded polymorphism, the technique used explained in https://ocamllabs.github.io/higher/lightweight-higher-kinded-polymorphism.pdf
*)
module StateMonad = struct
type ('s, 'a) m = 's -> 's * 'a
View gist:4d963db5b9af8e7ddfd5
type t =
| Pair of t * t
| Number of int
| Function of string (* or what? *)
let rec empty = Pair (empty, empty) (* make a looped value *)
let is_empty t = match t with
| Pair (t1, t2) -> t == t1 && t == t2 (* using pointer equality *)
| _ -> false
View gist:1f08efcd2a1fb7daef83
let (&) = (@@)
module Array = struct
include Array
let fold_lefti f st a =
let st = ref st in
Array.iteri (fun i a -> st := f !st i a) a;
!st
end
View recrec.ml
(*
ocamlfind ocamlopt -o recrec -package compiler-libs.common -linkpkg recrec.ml
*)
open List
open Format
let (&) = (@@)
module I() = TypedtreeIter.MakeIterator(struct
@camlspotter
camlspotter / 4.02.3+curried-constr.diff
Created Sep 1, 2015
DIFF between OCaml 4.02.3 and 4.02.3+curried-constr
View 4.02.3+curried-constr.diff
diff --git a/README_curried_constr.md b/README_curried_constr.md
new file mode 100644
index 0000000..12ed175
--- /dev/null
+++ b/README_curried_constr.md
@@ -0,0 +1,66 @@
+Variant constructors as functions
+==================================
+
+Suppose we have:
View gist:a8952a5fdf7298c59b9b
open Format
let rec hovb ppf = function
| 0 -> ()
| n ->
fprintf ppf "(@[<hov>-----------------------------------%03d@," n;
hovb ppf (n-1);
fprintf ppf "@])"
let rec b ppf = function
View fx_quote_filler.ml
(*
(* CR jfuruse: なんたら *) というのは前職でのコードレビューの書き方で、私の癖になっている。すべて、「私ならば…こうするかな?」が省略されています。
私ならやっつけモードでこう書く、という例です。人様のコードを元にしているので、ほんとにこう書くのかよ?という突っ込みはありかと思います。
元コードも実際のものを簡略化されたものだそうですので、私の提案コードのように書きたいけれども実は書けないんだ!ということもあるでしょう。
OCaml のプログラミングスタイルは決まったものはなくいろいろと流儀があります。その一つと思ってください。
*)
You can’t perform that action at this time.