Skip to content

Instantly share code, notes, and snippets.

(*
(* CR jfuruse: なんたら *) というのは前職でのコードレビューの書き方で、私の癖になっている。すべて、「私ならば…こうするかな?」が省略されています。
私ならやっつけモードでこう書く、という例です。人様のコードを元にしているので、ほんとにこう書くのかよ?という突っ込みはありかと思います。
元コードも実際のものを簡略化されたものだそうですので、私の提案コードのように書きたいけれども実は書けないんだ!ということもあるでしょう。
OCaml のプログラミングスタイルは決まったものはなくいろいろと流儀があります。その一つと思ってください。
*)
@camlspotter
camlspotter / gist:3121708
Created July 16, 2012 09:12
相互再帰した二つの型を別モジュールで定義する方法二つ
module Ex1 = struct
(* まず相互再帰した型を一モジュールで作り、その後別モジュールに分離する例 *)
module AB = struct
type a = A | AA of b
and b = B | BB of a
let a_f = function A -> B | AA b -> b
let b_f = function B -> A | BB a -> a
end
@camlspotter
camlspotter / gist:5629762
Last active December 17, 2015 15:09
適当に重み付けして高得点から並べてみました。うーん。納得できるのもあるし、えってのもある。 えええ俺だけ行った事の無い、わひろ閉店?ああ、住所が違うから移転前のか。焦った。 Yong Huat は… Joo Chiat と East coast の交差点にあるきちゃないホッケンミーの店だがそんな美味いのか? Puteri Mas はドリアンパフの店。納得の高得点。 Coriander は洋風の店、つい最近出来た Geylang Lor 29 は有名なホッケンミー Katsuya はトンカツの店なんだけど…日本人としてはどうもねえ Easter & Northern Dumpling は納得。ただこないだビールをハルビンからカールスバーグに変えた。残念すぎ Joo Chiat Prawn…
[ { "score": 300, "name": "(Closed) Wahiro",
"address": "112 East Coast Road",
"geo": [ 1.30501126709, 103.905173164 ] },
{ "score": 300, "name": "Yong Huat", "address": "125/127 East Coast Road",
"geo": [ 1.306044, 103.904794 ] },
{ "score": 300, "name": "Puteri Mas (Joo Chiat)",
"address": "475A Joo Chiat Road", "geo": [ 1.3063423, 103.904712 ] },
{ "score": 297, "name": "Coriander", "address": "220 East Coast Road",
"geo": [ 1.3073885145, 103.907421243 ] },
{ "score": 294, "name": "Geylang Lor 29 Fried Hokkien Mee",
open Spotlib.Spot
open GapiUtils.Infix
open GapiLens.Infix
open GapiLens.StateInfix
open GapiMonad.SessionM
module OAuth2 = GapiOAuth2
module Conv = GapiConversation
module Service = GapiService
module Id = struct
let name = "pa_fun_fields"
let version = "1.0"
end
open Camlp4
module Make (Syntax : Sig.Camlp4Syntax) = struct
include Syntax
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)
(* 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
(*
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
@camlspotter
camlspotter / gist:96b01590db525344d92a
Created September 23, 2014 11:12
Message passing by record labels, variants, GADTs and polymorphic variants.
open Printf
module ByMonomorphicRecord = struct
(* Interface by a monomorphic record *)
type point = {
get : unit -> int;
set : int -> unit;
print : unit -> unit;
}
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