This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let | |
((Fib/0 | |
(let* | |
((fib/1008 | |
(lambda (n/1009) | |
(if (not (equal n/1009 0)) | |
(if (not(equal n/1009 1)) | |
(+ (funcall fib/1008 (- n/1009 1)) (funcall fib/1008 (- n/1009 2))) | |
1) | |
0)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec fib = function | 0 -> 0 | 1 -> 1 | n -> fib (n-1) + fib (n-2) | |
(* Output of -dlambda *) | |
(setglobal Fib! | |
(letrec | |
(fib/1008 | |
(function n/1009 | |
(if (!= n/1009 0) | |
(if (!= n/1009 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
(* CR jfuruse: なんたら *) というのは前職でのコードレビューの書き方で、私の癖になっている。すべて、「私ならば…こうするかな?」が省略されています。 | |
私ならやっつけモードでこう書く、という例です。人様のコードを元にしているので、ほんとにこう書くのかよ?という突っ込みはありかと思います。 | |
元コードも実際のものを簡略化されたものだそうですので、私の提案コードのように書きたいけれども実は書けないんだ!ということもあるでしょう。 | |
OCaml のプログラミングスタイルは決まったものはなくいろいろと流儀があります。その一つと思ってください。 | |
*) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
ocamlfind ocamlopt -o recrec -package compiler-libs.common -linkpkg recrec.ml | |
*) | |
open List | |
open Format | |
let (&) = (@@) | |
module I() = TypedtreeIter.MakeIterator(struct |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Printf | |
module ByMonomorphicRecord = struct | |
(* Interface by a monomorphic record *) | |
type point = { | |
get : unit -> int; | |
set : int -> unit; | |
print : unit -> unit; | |
} |