This file contains hidden or 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 LazyFix = struct | |
| let rec fix f = f (lazy (fix f)) | |
| let f_open = fun clo (x : int) -> | |
| if x <= 0 then x else (snd (Lazy.force clo)) (x - 1) | |
| let g_open = fun clo (x : int) -> | |
| if x <= 0 then x else (fst (Lazy.force clo)) (x - 1) | |
| let clo = fix (fun clo -> f_open clo, g_open clo) |
This file contains hidden or 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 first f (x, y) = (f x, y) | |
| (** A more efficient version of List.concat. *) | |
| let list_concat ll = List.rev (List.fold_left (fun a b -> List.rev_append b a) [] ll) | |
| module type Monoid = sig | |
| type t | |
| val mempty : t | |
| val mappend : t -> t -> t | |
| val mconcat : t list -> t |
This file contains hidden or 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 first f (x, y) = (f x, y) | |
| (** A more efficient version of List.concat. *) | |
| let list_concat ll = List.rev (List.fold_left (fun a b -> List.rev_append b a) [] ll) | |
| module type Monoid = sig | |
| type t | |
| val mempty : t | |
| val mappend : t -> t -> t | |
| val mconcat : t list -> t |
This file contains hidden or 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 symbol = string | |
| module Env = Map.Make (String) | |
| type binary_op = Add | Sub | Mul | Div | |
| module Type = struct | |
| type t = | |
| | Unit | Int |
This file contains hidden or 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 f = | |
| FUN t -> fun l -> | |
| case l of | |
| | Nil [t] -> None [t] | |
| | Cons [t] x _ -> Some [t] x |
This file contains hidden or 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
| head : forall x . List x -> Maybe x | |
| head = /\(t : *) . \(l : List t) -> | |
| case l of | |
| | Cons [t] x _ -> Just [t] x | |
| | Nil [t] -> Nothing [t] |
This file contains hidden or 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 ('a, 'b) tmp_results = | |
| | Nada | |
| | Other of ('a, 'b) tmp_result | |
| constraint 'b = < | |
| to_str : string; | |
| pack : ('a,'b) tmp_results; | |
| unpack: 'a; | |
| .. | |
| > |
This file contains hidden or 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 t1 = [`Foo] | |
| let name1 = function `Foo -> "foo" | |
| type t2 = [t1 | `Bar] | |
| let name2 = function #t1 as f -> name1 f | `Bar -> "bar" |
This file contains hidden or 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 test1 () = | |
| let tbl = Hashtbl.create 16 in | |
| let z = Big_int.big_int_of_string "3242314122423341231" in | |
| Hashtbl.add tbl z (); | |
| Hashtbl.find tbl z | |
| let test2 () = | |
| let tbl = Hashtbl.create 16 in | |
| let z1 = Big_int.big_int_of_string "3242314122423341231" in |
This file contains hidden or 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 partition a p = | |
| let len = Array.length a in | |
| let rec loop l r = | |
| if r = len then l | |
| else if p a.(r) then begin | |
| let tmp = a.(l) in | |
| a.(l) <- a.(r); | |
| a.(r) <- tmp; | |
| loop (l + 1) (r + 1) | |
| end else |