| Expected | Ocp-indent output | |
|---|---|---|
| 0 | ||
| 1 | (* this could be fixed, but we actually want to handle the first case | (* this could be fixed, but we actually want to handle the first case | 
| 2 | differently for when there is only one case (see next examples) *) | differently for when there is only one case (see next examples) *) | 
| 3 | let f x = function A -> x; | let f x = function A -> x; | 
| 4 | 2 | 2 | 
| 5 | | B -> y; | | B -> y; | 
| 6 | 3 | 3 | 
| 7 | ||
| 8 | (* if we were to fix to the case above, the second >>= would be below the _ | (* if we were to fix to the case above, the second >>= would be below the _ | 
| 9 | (test taken from js-fun) *) | (test taken from js-fun) *) | 
| 10 | let _ = | let _ = | 
| 11 | x | x | 
| 12 | >>= fun x -> | >>= fun x -> | 
| 13 | try x with _ -> () | try x with _ -> () | 
| 14 | >>= fun x -> | >>= fun x -> | 
| 15 | x | x | 
| 16 | ||
| 17 | (* (and also: the some_handling here would be below Not_found) *) | (* (and also: the some_handling here would be below Not_found) *) | 
| 18 | let _ = | let _ = | 
| 19 | try | try | 
| 20 | _ | _ | 
| 21 | with Not_found -> | with Not_found -> | 
| 22 | some_handling | some_handling | 
| 23 | ||
| 24 | let f = fun x -> | let f = fun x -> | 
| 25 | x | x | 
| 26 | ||
| 27 | let f = (fun x -> | let f = (fun x -> | 
| 28 | x | x | 
| 29 | ) | ) | 
| 30 | ||
| 31 | let f g = g @@ fun x -> | let f g = g @@ fun x -> | 
| 32 | x | x | 
| 33 | ||
| 34 | let f g = g @@ (fun x -> | let f g = g @@ (fun x -> | 
| 35 | x | x | 
| 36 | ) | ) | 
| 37 | ||
| 38 | ||
| 39 | (* the above should probably be consistent with: *) | (* the above should probably be consistent with: *) | 
| 40 | let f x y = y + match x with A -> | let f x y = y + match x with A -> | 
| 41 | 0 | 0 | 
| 42 | ||
| 43 | let f x y = y + (match x with A -> | let f x y = y + (match x with A -> | 
| 44 | 0 | 0 | 
| 45 | ) | ) | 
| 46 | ||
| 47 | (* wich means we may over-indent even when the block is non-closable *) | (* wich means we may over-indent even when the block is non-closable *) | 
| 48 | ||
| 49 | let f x y = y + match x with | let f x y = y + match x with | 
| 50 | | A -> 0 | | A -> 0 | 
| 51 | ||
| 52 | let f x y = y + (match x with | let f x y = y + (match x with | 
| 53 | | A -> 0 | | A -> 0 | 
| 54 | ) | ) | 
| 55 | ||
| 56 | let f x y = y + match x with | let f x y = y + match x with | 
| 57 | | A -> 0 | | A -> 0 | 
| 58 | ||
| 59 | let _ = | let _ = | 
| 60 | somefun | somefun | 
| 61 | (fun x -> | (fun x -> | 
| 62 | x); | x); | 
| 63 | somefun | somefun | 
| 64 | (if | (if | 
| 65 | bla | bla | 
| 66 | then | then | 
| 67 | bli); | bli); | 
| 68 | somefun | somefun | 
| 69 | (if bla then | (if bla then | 
| 70 | bli | bli | 
| 71 | else | else | 
| 72 | blu) | blu) | 
| 73 | ||
| 74 | let _ = | let _ = | 
| 75 | a | a | 
| 76 | ; | ; | 
| 77 | b | b | 
| 78 | ||
| 79 | (* Surprisingly, this is the indentation correpsonding to OCaml's interpretation | (* Surprisingly, this is the indentation correpsonding to OCaml's interpretation | 
| 80 | of this code. Indenting this accordingly may help users notice that they're | of this code. Indenting this accordingly may help users notice that they're | 
| 81 | doing something dubious. *) | doing something dubious. *) | 
| 82 | let b = `b | let b = `b | 
| 83 | let d = `d | let d = `d | 
| 84 | ;; | ;; | 
| 85 | let a = b | let a = b | 
| 86 | function·(_·:·[·`c·])·->·d | ····function·(_·:·[·`c·])·->·d | 
| 87 | ;; | ;; | 
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | let s1 = "No field 'install', but a field 'remove': install instructions \ | let s1 = "No field 'install', but a field 'remove': install instructions \ | 
| 1 | probably part of 'build'. Use the 'install' field or a .install \ | probably part of 'build'. Use the 'install' field or a .install \ | 
| 2 | file" | file" | 
| 3 | ||
| 4 | let x = | let x = | 
| 5 | cond 40 `Warning | cond 40 `Warning | 
| 6 | "Package uses flags that aren't recognised by earlier versions in \ | "Package uses flags that aren't recognised by earlier versions in \ | 
| 7 | OPAM 1.2 branch. At the moment, you should use a tag \"flags:foo\" \ | OPAM 1.2 branch. At the moment, you should use a tag \"flags:foo\" \ | 
| 8 | instead for compatibility" | instead for compatibility" | 
| 9 | ~detail:alpha_flags | ~detail:alpha_flags | 
| 10 | (alpha_flags <> []) | (alpha_flags <> []) | 
| 11 | ||
| 12 | let s2 = "bla bla | let s2 = "bla bla | 
| 13 | bli bli \ | bli bli \ | 
| 14 | blo" | blo" | 
| 15 | ||
| 16 | let s3 = "\ | let s3 = "\ | 
| 17 | " | " | 
| 18 | ||
| 19 | let s4 = " \ | let s4 = " \ | 
| 20 | " | " | 
| 21 | ||
| 22 | let s5 = " \ | let s5 = " \ | 
| 23 | \ | \ | 
| 24 | " | " | 
| 25 | ||
| 26 | let s6 = " | let s6 = " | 
| 27 | " | " | 
| 28 | ||
| 29 | let s7 = " | let s7 = " | 
| 30 | " | " | 
| 31 | ||
| 32 | let c1 = ' | let c1 = ' | 
| 33 | ' | ···········' | 
| 34 | ||
| 35 | let x1 = f x ' | let x1 = f x ' | 
| 36 | '·y | ···············'·y | 
| 37 | z | z | 
| 38 | ||
| 39 | let zz = "\ | let zz = "\ | 
| 40 | ||
| 41 | s \ | s \ | 
| 42 | \ | \ | 
| 43 | " | " | 
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | type _ term = | type _ term = | 
| 1 | | Int : int -> int term | | Int : int -> int term | 
| 2 | | Add : (int -> int -> int) term | | Add : (int -> int -> int) term | 
| 3 |   | App : ('b -> 'a) term * 'b term -> 'a term |   | App : ('b -> 'a) term * 'b term -> 'a term | 
| 4 | ||
| 5 | let rec eval : type a. a term -> a = function | let rec eval : type a. a term -> a = function | 
| 6 | | Int n -> n (* a = int *) | | Int n -> n (* a = int *) | 
| 7 | | Add -> (fun x y -> x+y) (* a = int -> int -> int *) | | Add -> (fun x y -> x+y) (* a = int -> int -> int *) | 
| 8 | | App(f,x) -> (eval f) (eval x) | | App(f,x) -> (eval f) (eval x) | 
| 9 | (* eval called at types (b->a) and b for fresh b *) | (* eval called at types (b->a) and b for fresh b *) | 
| 10 | ||
| 11 | let two = eval (App (App (Add, Int 1), Int 1)) | let two = eval (App (App (Add, Int 1), Int 1)) | 
| 12 | ||
| 13 | let rec sum : type a. a term -> _ = fun x -> | let rec sum : type a. a term -> _ = fun x -> | 
| 14 | let y = | let y = | 
| 15 | match x with | match x with | 
| 16 | | Int n -> n | | Int n -> n | 
| 17 | | Add -> 0 | | Add -> 0 | 
| 18 | | App(f,x) -> sum f + sum x | | App(f,x) -> sum f + sum x | 
| 19 | in y + 1 | in y + 1 | 
| 20 | ||
| 21 | type _ typ = | type _ typ = | 
| 22 | | Int : int typ | | Int : int typ | 
| 23 | | String : string typ | | String : string typ | 
| 24 |   | Pair : 'a typ * 'b typ -> ('a * 'b) typ |   | Pair : 'a typ * 'b typ -> ('a * 'b) typ | 
| 25 | ||
| 26 | let rec to_string: type t. t typ -> t -> string = | let rec to_string: type t. t typ -> t -> string = | 
| 27 | fun t x -> | fun t x -> | 
| 28 | ····match·t·with | ··match·t·with | 
| 29 | ····|·Int·->·string_of_int·x | ··|·Int·->·string_of_int·x | 
| 30 | ····|·String·->·Printf.sprintf·"%S"·x | ··|·String·->·Printf.sprintf·"%S"·x | 
| 31 | ····|·Pair(t1,t2)·-> | ··|·Pair(t1,t2)·-> | 
| 32 | ······let·(x1,·x2)·=·x·in | ····let·(x1,·x2)·=·x·in | 
| 33 | ······Printf.sprintf·"(%s,%s)"·(to_string·t1·x1)·(to_string·t2·x2) | ····Printf.sprintf·"(%s,%s)"·(to_string·t1·x1)·(to_string·t2·x2) | 
| 34 | ||
| 35 | type (_,_) eq = Eq : ('a,'a) eq | type (_,_) eq = Eq : ('a,'a) eq | 
| 36 | ||
| 37 | let cast : type a b. (a,b) eq -> a -> b = fun Eq x -> x | let cast : type a b. (a,b) eq -> a -> b = fun Eq x -> x | 
| 38 | ||
| 39 | let rec eq_type : type a b. a typ -> b typ -> (a,b) eq option = | let rec eq_type : type a b. a typ -> b typ -> (a,b) eq option = | 
| 40 | fun a b -> | fun a b -> | 
| 41 | ····match·a,·b·with | ··match·a,·b·with | 
| 42 | ····|·Int,·Int·->·Some·Eq | ··|·Int,·Int·->·Some·Eq | 
| 43 | ····|·String,·String·->·Some·Eq | ··|·String,·String·->·Some·Eq | 
| 44 | ····|·Pair(a1,a2),·Pair(b1,b2)·-> | ··|·Pair(a1,a2),·Pair(b1,b2)·-> | 
| 45 | ······begin·match·eq_type·a1·b1,·eq_type·a2·b2·with | ····begin·match·eq_type·a1·b1,·eq_type·a2·b2·with | 
| 46 | ········|·Some·Eq,·Some·Eq·->·Some·Eq | ······|·Some·Eq,·Some·Eq·->·Some·Eq | 
| 47 | ········|·_·->·None | ······|·_·->·None | 
| 48 | ······end | ····end | 
| 49 | ····|·_·->·None | ··|·_·->·None | 
| 50 | ||
| 51 | type dyn = Dyn : 'a typ * 'a -> dyn | type dyn = Dyn : 'a typ * 'a -> dyn | 
| 52 | ||
| 53 | let get_dyn : type a. a typ -> dyn -> a option = | let get_dyn : type a. a typ -> dyn -> a option = | 
| 54 | fun a (Dyn(b,x)) -> | fun a (Dyn(b,x)) -> | 
| 55 | ····match·eq_type·a·b·with | ··match·eq_type·a·b·with | 
| 56 | ····|·None·->·None | ··|·None·->·None | 
| 57 | ····|·Some·Eq·->·Some·x | ··|·Some·Eq·->·Some·x | 
| 58 | ||
| 59 | let _ = | let _ = | 
| 60 | let f: type a. a list -> int = | let f: type a. a list -> int = | 
| 61 | fun _x -> 42 | fun _x -> 42 | 
| 62 | in | in | 
| 63 | f [] | f [] | 
| 64 | ||
| 65 | let nth t n = | let nth t n = | 
| 66 | if n < 0 then None else | if n < 0 then None else | 
| 67 |     let rec nth_aux: type b. ('a, b) t -> int -> 'a option = fun t n -> |     let rec nth_aux: type b. ('a, b) t -> int -> 'a option = fun t n -> | 
| 68 | match t with | match t with | 
| 69 | | Empty -> None | | Empty -> None | 
| 70 | | Node (a, t) -> if n = 0 then Some a else nth_aux t (n-1) | | Node (a, t) -> if n = 0 then Some a else nth_aux t (n-1) | 
| 71 | in | in | 
| 72 | nth_aux t n | nth_aux t n | 
| 73 | ||
| 74 | let rec f : type a b. a = function | let rec f : type a b. a = function | 
| 75 | | _ -> assert false | | _ -> assert false | 
| 76 | and g : type a. a = function | and g : type a. a = function | 
| 77 | | _ -> assert false | | _ -> assert false | 
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | let () = | let () = | 
| 1 | foo.bar <- | foo.bar <- | 
| 2 | f x | f x | 
| 3 | y z | y z | 
| 4 | ||
| 5 | let should_check_can_sell_and_marking regulatory_regime = | let should_check_can_sell_and_marking regulatory_regime = | 
| 6 | match z with | match z with | 
| 7 | | `foo | | `foo | 
| 8 | -> some_function | -> some_function | 
| 9 | argument | argument | 
| 10 | (* The above typically occurs in a multi-pattern match clause, so the clause | (* The above typically occurs in a multi-pattern match clause, so the clause | 
| 11 | expression is on a line by itself. This is the more typical way a long | expression is on a line by itself. This is the more typical way a long | 
| 12 | single-pattern match clause would be written: *) | single-pattern match clause would be written: *) | 
| 13 | let should_check_can_sell_and_marking regulatory_regime = | let should_check_can_sell_and_marking regulatory_regime = | 
| 14 | match z with | match z with | 
| 15 | | `foo -> | | `foo -> | 
| 16 | some_function | some_function | 
| 17 | argument | argument | 
| 18 | ||
| 19 | let f = fun x -> | let f = fun x -> | 
| 20 | ghi | ghi | 
| 21 | x | x | 
| 22 | ||
| 23 | (* common *) | (* common *) | 
| 24 | let x = | let x = | 
| 25 | try x with | try x with | 
| 26 | | a -> b | | a -> b | 
| 27 | | c -> d | | c -> d | 
| 28 | let x = try x with | let x = try x with | 
| 29 | | a -> b | | a -> b | 
| 30 | | c -> d | | c -> d | 
| 31 | let x = | let x = | 
| 32 | try x | try x | 
| 33 | with | with | 
| 34 | | a -> b | | a -> b | 
| 35 | | c -> d | | c -> d | 
| 36 | ||
| 37 | let z = | let z = | 
| 38 | some_function | some_function | 
| 39 | argument | argument | 
| 40 | ||
| 41 | ||
| 42 | ||
| 43 | let () = | let () = | 
| 44 | f a b ~c:c | f a b ~c:c | 
| 45 | d | d | 
| 46 | ||
| 47 | let () = | let () = | 
| 48 | f a b ~c:1. | f a b ~c:1. | 
| 49 | d | d | 
| 50 | ||
| 51 | let () = | let () = | 
| 52 | My_module.f a b ~c:c | My_module.f a b ~c:c | 
| 53 | d | d | 
| 54 | ||
| 55 | (* This last case is where Tuareg is inconsistent with the others. *) | (* This last case is where Tuareg is inconsistent with the others. *) | 
| 56 | let () = | let () = | 
| 57 | My_module.f a b ~c:1. | My_module.f a b ~c:1. | 
| 58 | d | d | 
| 59 | ||
| 60 | ||
| 61 | ||
| 62 | let () = | let () = | 
| 63 | messages := | messages := | 
| 64 | Message_store.create (Session_id.of_string "") | Message_store.create (Session_id.of_string "") | 
| 65 | (* Tuareg indents these lines too far to the left. *) | (* Tuareg indents these lines too far to the left. *) | 
| 66 | "herd-retransmitter" | "herd-retransmitter" | 
| 67 | Message_store.Message_size.Byte | Message_store.Message_size.Byte | 
| 68 | ||
| 69 | ||
| 70 | ||
| 71 | let () = | let () = | 
| 72 |   raise (Bug ("foo" |   raise (Bug ("foo" | 
| 73 | (* In this and similar cases, we want the subsequent lines to | (* In this and similar cases, we want the subsequent lines to | 
| 74 | align with the first expression. *) | align with the first expression. *) | 
| 75 | ^ "bar")); | ^ "bar")); | 
| 76 |   raise (Bug ("foo" ^ "quux" |   raise (Bug ("foo" ^ "quux" | 
| 77 | ^ "bar")); | ^ "bar")); | 
| 78 | raise (Bug (foo + quux | raise (Bug (foo + quux | 
| 79 | ^ "bar")); | ^ "bar")); | 
| 80 | raise (Bug ((foo + quux) | raise (Bug ((foo + quux) | 
| 81 | ^ "bar")) | ^ "bar")) | 
| 82 | ||
| 83 | (* Except in specific cases, we want the argument indented relative to the | (* Except in specific cases, we want the argument indented relative to the | 
| 84 | function being called. (Exceptions include "fun" arguments where the line | function being called. (Exceptions include "fun" arguments where the line | 
| 85 | ends with "->" and subsequent lines beginning with operators, like above.) *) | ends with "->" and subsequent lines beginning with operators, like above.) *) | 
| 86 | let () = | let () = | 
| 87 | Some (Message_store.create s | Some (Message_store.create s | 
| 88 | "herd-retransmitter" ~unlink:true Message_store.Message_size.Byte) | "herd-retransmitter" ~unlink:true Message_store.Message_size.Byte) | 
| 89 | ||
| 90 | ||
| 91 | ||
| 92 | (* We like the indentation of most arguments, but want to get back towards the | (* We like the indentation of most arguments, but want to get back towards the | 
| 93 | left margin in a few special cases: *) | left margin in a few special cases: *) | 
| 94 | let _ = | let _ = | 
| 95 | foo (bar (fun x -> (* special: "fun _ ->" at EOL *) | foo (bar (fun x -> (* special: "fun _ ->" at EOL *) | 
| 96 | baz)) (* assume no more arguments to "bar" *) | baz)) (* assume no more arguments to "bar" *) | 
| 97 | let _ = | let _ = | 
| 98 | foo | foo | 
| 99 | ~a_long_field_name:(check (fun bar -> | ~a_long_field_name:(check (fun bar -> | 
| 100 | baz)) | baz)) | 
| 101 | let _ = | let _ = | 
| 102 | foo ~a_long_field_name:(check (fun bar -> | foo ~a_long_field_name:(check (fun bar -> | 
| 103 | baz)) | baz)) | 
| 104 | let _ = | let _ = | 
| 105 | foo (bar (quux (fnord (fun x -> (* any depth *) | foo (bar (quux (fnord (fun x -> (* any depth *) | 
| 106 | baz)))) | baz)))) | 
| 107 | ||
| 108 | (* We also wanted to tweak the operator indentation, making operators like <= | (* We also wanted to tweak the operator indentation, making operators like <= | 
| 109 | not special cases in contexts like this: *) | not special cases in contexts like this: *) | 
| 110 | let _ = | let _ = | 
| 111 | assert (foo (bar + baz | assert (foo (bar + baz | 
| 112 | <= quux)) (* lined up under left argument to op, | <= quux)) (* lined up under left argument to op, | 
| 113 | sim. to ^ above *) | sim. to ^ above *) | 
| 114 | (* Sim. indentation of if conditions: *) | (* Sim. indentation of if conditions: *) | 
| 115 | let _ = | let _ = | 
| 116 | if (a | if (a | 
| 117 | <= b) | <= b) | 
| 118 | then () | then () | 
| 119 | let _ = | let _ = | 
| 120 | (* Comparisons are different than conditionals; we don't regard them as | (* Comparisons are different than conditionals; we don't regard them as | 
| 121 | conceptually part of the [if] expression. *) | conceptually part of the [if] expression. *) | 
| 122 | if a | if a | 
| 123 | <= b | <= b | 
| 124 | then () | then () | 
| 125 | let _ = | let _ = | 
| 126 | (* We regard the outermost condition terms as conceptually part of the [if] | (* We regard the outermost condition terms as conceptually part of the [if] | 
| 127 | expression and indent accordingly. Whether [&&] or [||], conditionals | expression and indent accordingly. Whether [&&] or [||], conditionals | 
| 128 | effectively state lists of conditions for [then]. *) | effectively state lists of conditions for [then]. *) | 
| 129 | if Edge_adjustment.is_zero arb.cfg.extra_edge | if Edge_adjustment.is_zero arb.cfg.extra_edge | 
| 130 | && 0. = sys.plugs.edge_backoff | && 0. = sys.plugs.edge_backoff | 
| 131 | && 0. = zero_acvol_edge_backoff | && 0. = zero_acvol_edge_backoff | 
| 132 | then 0. | then 0. | 
| 133 | else 1. | else 1. | 
| 134 | let _ = | let _ = | 
| 135 | if | if | 
| 136 | Edge_adjustment.is_zero arb.cfg.extra_edge | Edge_adjustment.is_zero arb.cfg.extra_edge | 
| 137 | && 0. = sys.plugs.edge_backoff | && 0. = sys.plugs.edge_backoff | 
| 138 | && 0. = zero_acvol_edge_backoff | && 0. = zero_acvol_edge_backoff | 
| 139 | then 0. | then 0. | 
| 140 | else 1. | else 1. | 
| 141 | let _ = | let _ = | 
| 142 | let entries = List.filter (Lazy.force transferstati) ~f:(fun ts -> | let entries = List.filter (Lazy.force transferstati) ~f:(fun ts -> | 
| 143 | Pcre.pmatch ~pat ts.RQ.description | Pcre.pmatch ~pat ts.RQ.description | 
| 144 | ) in | ) in | 
| 145 | x | x | 
| 146 | ||
| 147 | (* combination of operator at BOL and -> at EOL: *) | (* combination of operator at BOL and -> at EOL: *) | 
| 148 | let _ = | let _ = | 
| 149 | Shell.ssh_lines x | Shell.ssh_lines x | 
| 150 | |! List.map ~f:(f (g (fun x -> | |! List.map ~f:(f (g (fun x -> | 
| 151 | ·······let·name,·path·=·String.lsplit2_exn·~on:'|'·x·in | ····let·name,·path·=·String.lsplit2_exn·~on:'|'·x·in | 
| 152 | ·······String.strip·name,·String.strip·path))) | ····String.strip·name,·String.strip·path))) | 
| 153 | ||
| 154 | (* open paren ending line like begin *) | (* open paren ending line like begin *) | 
| 155 | let _ = | let _ = | 
| 156 | if a (p ^/ "s") [ e ] = Ok () then `S ( | if a (p ^/ "s") [ e ] = Ok () then `S ( | 
| 157 | let label count = | let label count = | 
| 158 | sprintf "%d s" c ^ if c = 1 then ":" else "s" | sprintf "%d s" c ^ if c = 1 then ":" else "s" | 
| 159 | in | in | 
| 160 | x | x | 
| 161 | ) | ) | 
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | let f = function | let f = function | 
| 1 | | zoo -> begin | | zoo -> begin | 
| 2 | foo; | foo; | 
| 3 | bar; | bar; | 
| 4 | end | end | 
| 5 | ;; | ;; | 
| 6 | let g = function | let g = function | 
| 7 | | zoo -> ( | | zoo -> ( | 
| 8 | foo; | foo; | 
| 9 | bar; | bar; | 
| 10 | ) | ) | 
| 11 | ;; | ;; | 
| 12 | let () = | let () = | 
| 13 | begin match foo with | begin match foo with | 
| 14 | ········|·Bar·->·snoo | ··|·Bar·->·snoo | 
| 15 | end | end | 
| 16 | ;; | ;; | 
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | (* preferred list style *) | (* preferred list style *) | 
| 1 | let z = | let z = | 
| 2 | f | f | 
| 3 | [ y | [ y | 
| 4 | ; foo ~f:(fun () -> | ; foo ~f:(fun () -> | 
| 5 | arg) | arg) | 
| 6 | ] | ] | 
| 7 | ;; | ;; | 
| 8 | let z = | let z = | 
| 9 | f | f | 
| 10 | [ y | [ y | 
| 11 | ; foo ~f:(fun () -> | ; foo ~f:(fun () -> | 
| 12 | arg | arg | 
| 13 | ) | ) | 
| 14 | ] | ] | 
| 15 | ;; | ;; | 
| 16 | ||
| 17 | (* legacy list style *) | (* legacy list style *) | 
| 18 | let _ = | let _ = | 
| 19 | [ f (fun x -> | [ f (fun x -> | 
| 20 | x); | x); | 
| 21 | f (fun x -> | f (fun x -> | 
| 22 | x); | x); | 
| 23 | f (fun x -> | f (fun x -> | 
| 24 | x); | x); | 
| 25 | ] | ] | 
| 26 | let _ = | let _ = | 
| 27 | [ f (fun x -> | [ f (fun x -> | 
| 28 | x | x | 
| 29 | ); | ); | 
| 30 | f (fun x -> | f (fun x -> | 
| 31 | x | x | 
| 32 | ); | ); | 
| 33 | f (fun x -> | f (fun x -> | 
| 34 | x | x | 
| 35 | ); | ); | 
| 36 | ] | ] | 
| 37 | ;; | ;; | 
| 38 | let _ = | let _ = | 
| 39 | [f (fun x -> | [f (fun x -> | 
| 40 | x | x | 
| 41 | ); | ); | 
| 42 | f (fun x -> | f (fun x -> | 
| 43 | x | x | 
| 44 | ); | ); | 
| 45 | f (fun x -> | f (fun x -> | 
| 46 | x | x | 
| 47 | ); | ); | 
| 48 | ] | ] | 
| 49 | ;; | ;; | 
| 50 | ||
| 51 | let _ = | let _ = | 
| 52 | x | x | 
| 53 | >>= fun x -> | >>= fun x -> | 
| 54 | (try x with _ -> ()) | (try x with _ -> ()) | 
| 55 | >>= fun x -> | >>= fun x -> | 
| 56 | try x with _ -> () | try x with _ -> () | 
| 57 | >>= fun x -> | >>= fun x -> | 
| 58 | x | x | 
| 59 | ;; | ;; | 
| 60 | ||
| 61 | let () = | let () = | 
| 62 | expr | expr | 
| 63 | >>| function | >>| function | 
| 64 | | x -> 3 | | x -> 3 | 
| 65 | | y -> 4 | | y -> 4 | 
| 66 | ;; | ;; | 
| 67 | ||
| 68 | let () = | let () = | 
| 69 | expr | expr | 
| 70 | >>| fun z -> match z with | >>| fun z -> match z with | 
| 71 | ···············|·x·->·3 | ··|·x·->·3 | 
| 72 | ···············|·y·->·4 | ··|·y·->·4 | 
| 73 | ;; | ;; | 
| 74 | ||
| 75 | let () = | let () = | 
| 76 | expr | expr | 
| 77 | >>| fun z -> function | >>| fun z -> function | 
| 78 | | x -> 3 | | x -> 3 | 
| 79 | | y -> 4 | | y -> 4 | 
| 80 | ;; | ;; | 
| 81 | ||
| 82 | let () = | let () = | 
| 83 | my_func () >>= function | my_func () >>= function | 
| 84 | | A -> 0 | | A -> 0 | 
| 85 | | B -> 0 | | B -> 0 | 
| 86 | ;; | ;; | 
| 87 | ||
| 88 | let () = | let () = | 
| 89 | my_func () >>= (function | my_func () >>= (function | 
| 90 | | A -> 0 | | A -> 0 | 
| 91 | | B -> 0) | | B -> 0) | 
| 92 | ;; | ;; | 
| 93 | ||
| 94 | let () = | let () = | 
| 95 | expr | expr | 
| 96 | >>| function | >>| function | 
| 97 | | x -> 3 | | x -> 3 | 
| 98 | | y -> 4 | | y -> 4 | 
| 99 | ;; | ;; | 
| 100 | ||
| 101 | let () = | let () = | 
| 102 | expr | expr | 
| 103 | >>| (function | >>| (function | 
| 104 | | x -> 3 | | x -> 3 | 
| 105 | | y -> 4) | | y -> 4) | 
| 106 | ;; | ;; | 
| 107 | ||
| 108 | ||
| 109 | ||
| 110 | let f = | let f = | 
| 111 | f >>= m (fun f -> | f >>= m (fun f -> | 
| 112 | fun x -> | fun x -> | 
| 113 | y); | y); | 
| 114 | z | z | 
| 115 | ;; | ;; | 
| 116 | ||
| 117 | let f = | let f = | 
| 118 | f | f | 
| 119 | |> m (fun f -> | |> m (fun f -> | 
| 120 | fun x -> | fun x -> | 
| 121 | y | y | 
| 122 | ); | ); | 
| 123 | z | z | 
| 124 | ;; | ;; | 
| 125 | let f = | let f = | 
| 126 | f | f | 
| 127 | |> m (fun f -> | |> m (fun f -> | 
| 128 | fun x -> | fun x -> | 
| 129 | y); | y); | 
| 130 | z | z | 
| 131 | ;; | ;; | 
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | module M = | module M = | 
| 1 | Foo (G) | Foo (G) | 
| 2 | (H) | (H) | 
| 3 | ||
| 4 | module M = | module M = | 
| 5 | Foo | Foo | 
| 6 | (G) | (G) | 
| 7 | (struct | (struct | 
| 8 | let x | let x | 
| 9 | end) | end) | 
| 10 | (H) | (H) | 
| 11 | ||
| 12 | (* To me, this looks fine as it is. The rule seems fine as "indent arguments by | (* To me, this looks fine as it is. The rule seems fine as "indent arguments by | 
| 13 | 2". To illustrate, with a case where the functor name is longer: *) | 2". To illustrate, with a case where the functor name is longer: *) | 
| 14 | module M = | module M = | 
| 15 | Functor (G) | Functor (G) | 
| 16 | (H) | (H) | 
| 17 | (I) | (I) | 
| 18 | ||
| 19 | ||
| 20 | ||
| 21 | include Foo (struct | include Foo (struct | 
| 22 | let x | let x | 
| 23 | end) (struct | end) (struct | 
| 24 | let y | let y | 
| 25 | end) | end) | 
| 26 | ||
| 27 | include | include | 
| 28 | Foo (struct | Foo (struct | 
| 29 | ······let·x | ····let·x | 
| 30 | ····end)·(struct | ··end)·(struct | 
| 31 | ······let·y | ····let·y | 
| 32 | ····end) | ··end) | 
| 33 | ||
| 34 | include | include | 
| 35 | Foo | Foo | 
| 36 | (struct | (struct | 
| 37 | let x | let x | 
| 38 | end) (struct | end) (struct | 
| 39 | ······let·y | ····let·y | 
| 40 | ····end) | ··end) | 
| 41 | ||
| 42 | include Persistent.Make | include Persistent.Make | 
| 43 | ··(struct·let·version·=·1·end) | ····(struct·let·version·=·1·end) | 
| 44 | ··(Stable.Cr_soons_or_pending.V1) | ····(Stable.Cr_soons_or_pending.V1) | 
| 45 | ||
| 46 | include Persistent.Make | include Persistent.Make | 
| 47 | ··(struct | ····(struct | 
| 48 | ····let·version·=·1 | ······let·version·=·1 | 
| 49 | ··end) | ····end) | 
| 50 | ··(Stable.Cr_soons_or_pending.V1) | ····(Stable.Cr_soons_or_pending.V1) | 
| 51 | ||
| 52 | include | include | 
| 53 | Persistent.Make | Persistent.Make | 
| 54 | (struct let version = 1 end) | (struct let version = 1 end) | 
| 55 | (Stable.Cr_soons_or_pending.V1) | (Stable.Cr_soons_or_pending.V1) | 
| 56 | ||
| 57 | include | include | 
| 58 | Persistent.Make | Persistent.Make | 
| 59 | (struct | (struct | 
| 60 | let version = 1 | let version = 1 | 
| 61 | end) | end) | 
| 62 | (Stable.Cr_soons_or_pending.V1) | (Stable.Cr_soons_or_pending.V1) | 
| 63 | ||
| 64 | module M = | module M = | 
| 65 | Foo (struct | Foo (struct | 
| 66 | ······let·x | ····let·x | 
| 67 | ····end)·(struct | ··end)·(struct | 
| 68 | ······let·y | ····let·y | 
| 69 | ····end) | ··end) | 
| 70 | ||
| 71 | module M : S = | module M : S = | 
| 72 | Make (M) | Make (M) | 
| 73 | module M : S with type t := int = | module M : S with type t := int = | 
| 74 | Make (M) | Make (M) | 
| 75 | ||
| 76 | ||
| 77 | ||
| 78 | module Simple_command(Arg:sig | module Simple_command(Arg:sig | 
| 79 | end) = struct end | end) = struct end | 
| 80 | ||
| 81 | module Simple_command(Arg : sig | module Simple_command(Arg : sig | 
| 82 | end) = struct end | end) = struct end | 
| 83 | ||
| 84 | module Simple_command (Arg:sig | module Simple_command (Arg:sig | 
| 85 | end) = struct end | end) = struct end | 
| 86 | ||
| 87 | module Simple_command (Arg : sig | module Simple_command (Arg : sig | 
| 88 | end) = struct end | end) = struct end | 
| 89 | ||
| 90 | module Simple_command | module Simple_command | 
| 91 | ··(Arg·:·sig | ····(Arg·:·sig | 
| 92 | ···end)·=·struct·end | ·····end)·=·struct·end | 
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | let f = function | let f = function | 
| 1 | | _ -> 0 | | _ -> 0 | 
| 2 | ;; | ;; | 
| 3 | ||
| 4 | let f x = match x with | let f x = match x with | 
| 5 | ··········|·_·->·0 | ··|·_·->·0 | 
| 6 | ;; | ;; | 
| 7 | ||
| 8 | let f = | let f = | 
| 9 | function | function | 
| 10 | | _ -> 0 | | _ -> 0 | 
| 11 | ;; | ;; | 
| 12 | ||
| 13 | let f x = | let f x = | 
| 14 | match x with | match x with | 
| 15 | | _ -> 0 | | _ -> 0 | 
| 16 | ;; | ;; | 
| 17 | ||
| 18 | let f x = | let f x = | 
| 19 | begin match x with | begin match x with | 
| 20 | ········|·_·->·0 | ··|·_·->·0 | 
| 21 | end | end | 
| 22 | ;; | ;; | 
| 23 | ||
| 24 | let check_price t = function | let check_price t = function | 
| 25 |   | { Exec. |   | { Exec. | 
| 26 | trade_at_settlement = (None | Some false); | trade_at_settlement = (None | Some false); | 
| 27 | } -> () | } -> () | 
| 28 | ||
| 29 | let check_price t = function | let check_price t = function | 
| 30 | | simpler -> () | | simpler -> () | 
| 31 | | other -> () | | other -> () | 
| 32 | ||
| 33 | (* Sometimes we like to write big alternations like this, in which case the | (* Sometimes we like to write big alternations like this, in which case the | 
| 34 | comment should typically align with the following clause. *) | comment should typically align with the following clause. *) | 
| 35 | let 0 = | let 0 = | 
| 36 | match x with | match x with | 
| 37 | | A | | A | 
| 38 | (* a *) | (* a *) | 
| 39 | -> a | -> a | 
| 40 | let 0 = | let 0 = | 
| 41 | match x with | match x with | 
| 42 | A | A | 
| 43 | (* a *) | (* a *) | 
| 44 | -> a | -> a | 
| 45 | ||
| 46 | let _ = | let _ = | 
| 47 | a | a | 
| 48 | || match a with | || match a with | 
| 49 | ·····|·a·->·true | ··|·a·->·true | 
| 50 | ·····|·b·->·false | ··|·b·->·false | 
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | type x = | type x = | 
| 1 |   { foo : int |   { foo : int | 
| 2 | ; bar : int | ; bar : int | 
| 3 | } | } | 
| 4 | ||
| 5 | let x = | let x = | 
| 6 |   { x with |   { x with | 
| 7 | foo = 3 | foo = 3 | 
| 8 | ; bar = 5 | ; bar = 5 | 
| 9 | } | } | 
| 10 | ||
| 11 | let x = | let x = | 
| 12 |   { (* blah blah blah *) |   { (* blah blah blah *) | 
| 13 | foo = 3 | foo = 3 | 
| 14 | ; bar = 5 | ; bar = 5 | 
| 15 | } | } | 
| 16 | ;; | ;; | 
| 17 | ||
| 18 | let x = | let x = | 
| 19 |   [{ x with |   [{ x with | 
| 20 | foo = 3 | foo = 3 | 
| 21 | ; bar = 5 | ; bar = 5 | 
| 22 | }] | }] | 
| 23 | ||
| 24 | let x = | let x = | 
| 25 |   [{ (* blah blah blah *) |   [{ (* blah blah blah *) | 
| 26 | ·····foo·=·3 | ····foo·=·3 | 
| 27 | ···;·bar·=·5 | ··;·bar·=·5 | 
| 28 | ···}] | ··}] | 
| 29 | ;; | ;; | 
| 30 | ||
| 31 | let x = | let x = | 
| 32 |   { M.x with |   { M.x with | 
| 33 | M. | M. | 
| 34 | foo = 3 | foo = 3 | 
| 35 | } | } | 
| 36 | ;; | ;; | 
| 37 | ||
| 38 | let x = | let x = | 
| 39 |   { x with |   { x with | 
| 40 | M. | M. | 
| 41 | foo = 3 | foo = 3 | 
| 42 | } | } | 
| 43 | ;; | ;; | 
| 44 | ||
| 45 | let x = | let x = | 
| 46 |   { M. |   { M. | 
| 47 | foo = 3 | foo = 3 | 
| 48 | } | } | 
| 49 | ;; | ;; | 
| 50 | ||
| 51 | let _ = | let _ = | 
| 52 |   { foo with |   { foo with | 
| 53 | Bar. | Bar. | 
| 54 | field1 = value1 | field1 = value1 | 
| 55 | ; field2 = value2 | ; field2 = value2 | 
| 56 | } | } | 
| 57 | ;; | ;; | 
| 58 | let _ = | let _ = | 
| 59 |   { foo |   { foo | 
| 60 | with Bar. | with Bar. | 
| 61 | ····field1·=·value1 | ······field1·=·value1 | 
| 62 | ··;·field2·=·value2 | ····;·field2·=·value2 | 
| 63 | } | } | 
| 64 | ;; | ;; | 
| 65 | ||
| 66 | (* multicomponent record module pathname *) | (* multicomponent record module pathname *) | 
| 67 | let _ = | let _ = | 
| 68 |   { A.B. |   { A.B. | 
| 69 | a = b | a = b | 
| 70 | ; c = d | ; c = d | 
| 71 | } | } | 
| 72 | ;; | ;; | 
| 73 | ||
| 74 | type t = | type t = | 
| 75 |   { a |   { a | 
| 76 | : something_lengthy list list | : something_lengthy list list | 
| 77 | [@default String.Map.empty] | [@default String.Map.empty] | 
| 78 | } | } | 
| 79 | ||
| 80 | type t = | type t = | 
| 81 |   { a |   { a | 
| 82 | : Something_lengthy.t list list | : Something_lengthy.t list list | 
| 83 | [@default String.Map.empty] | [@default String.Map.empty] | 
| 84 | } | } | 
| 85 | ||
| 86 | type t = | type t = | 
| 87 |   { a |   { a | 
| 88 | : something_lengthy list | : something_lengthy list | 
| 89 | list | list | 
| 90 | } | } | 
| 91 | ||
| 92 | type t = | type t = | 
| 93 |   { a |   { a | 
| 94 | : Something_lengthy.t list | : Something_lengthy.t list | 
| 95 | list | list | 
| 96 | } | } | 
| 97 | ||
| 98 | type t = | type t = | 
| 99 |   { a |   { a | 
| 100 | : Something_lengthy.t | : Something_lengthy.t | 
| 101 | list | list | 
| 102 | } | } | 
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | (* s *) | (* s *) | 
| 1 | ||
| 2 | let _ = | let _ = | 
| 3 | [%raise_structural_sexp | [%raise_structural_sexp | 
| 4 | "feature's tip is already an ancestor of new base" | "feature's tip is already an ancestor of new base" | 
| 5 | ····{·feature_tip·=·(old_tip·:·Rev.t) | ······{·feature_tip·=·(old_tip·:·Rev.t) | 
| 6 | ····;·new_base····=·(new_base·:·Rev.t) | ······;·new_base····=·(new_base·:·Rev.t) | 
| 7 | ····}] | ······}] | 
| 8 | ||
| 9 | let _ = | let _ = | 
| 10 | [%raise_structural_sexp "feature's tip is already an ancestor of new base" | [%raise_structural_sexp "feature's tip is already an ancestor of new base" | 
| 11 | ····{·feature_tip·=·(old_tip·:·Rev.t) | ····························{·feature_tip·=·(old_tip·:·Rev.t) | 
| 12 | ····;·new_base····=·(new_base·:·Rev.t) | ····························;·new_base····=·(new_base·:·Rev.t) | 
| 13 | ····} | ····························} | 
| 14 | ] | ] | 
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | (* Indentation that Jane Street needs to think about and make precise. | (* Indentation that Jane Street needs to think about and make precise. | 
| 1 | ||
| 2 | These are long term ideas, possibly even conflicting with other tests. *) | These are long term ideas, possibly even conflicting with other tests. *) | 
| 3 | ||
| 4 | ||
| 5 | ||
| 6 | (* js-args *) | (* js-args *) | 
| 7 | ||
| 8 | let _ = | let _ = | 
| 9 | let min_closing_backoff = | let min_closing_backoff = | 
| 10 | -. ( Hidden_float.expose (arb.cfg.base_edge @! Buy) | -. ( Hidden_float.expose (arb.cfg.base_edge @! Buy) | 
| 11 | ········+.·Hidden_float.expose·(arb.cfg.base_edge·@!·Sell)) | ···········+.·Hidden_float.expose·(arb.cfg.base_edge·@!·Sell)) | 
| 12 | in | in | 
| 13 | 0 | 0 | 
| 14 | ||
| 15 | ||
| 16 | ||
| 17 | (* js-type *) | (* js-type *) | 
| 18 | ||
| 19 | (* The following tests incorporate several subtle and different indentation | (* The following tests incorporate several subtle and different indentation | 
| 20 | ideas. Please consider this only a proposal for discussion, for now. | ideas. Please consider this only a proposal for discussion, for now. | 
| 21 | ||
| 22 | First, notice the display treatment of "(,)" tuples, analogous to "[;]" | First, notice the display treatment of "(,)" tuples, analogous to "[;]" | 
| 23 | lists. While "(,)" is an intensional combination of "()" and ",", unlike | lists. While "(,)" is an intensional combination of "()" and ",", unlike | 
| 24 | "[;]" lists, we believe "(,)" isn't too big a departure. Value expression | "[;]" lists, we believe "(,)" isn't too big a departure. Value expression | 
| 25 | analogies are included in js-type.ml, (meant to be) consistent with the | analogies are included in js-type.ml, (meant to be) consistent with the | 
| 26 | proposed type indentation. | proposed type indentation. | 
| 27 | ||
| 28 | Second, and more divergently, the proposed indentation of function types is | Second, and more divergently, the proposed indentation of function types is | 
| 29 | based on the idea of aligning the arguments, even the first argument, even | based on the idea of aligning the arguments, even the first argument, even | 
| 30 | where that means automatically inserting spaces within lines. This applies | where that means automatically inserting spaces within lines. This applies | 
| 31 | to the extra spaces in ":__unit" and "(____Config.Network.t" below. | to the extra spaces in ":__unit" and "(____Config.Network.t" below. | 
| 32 | ||
| 33 | We believe this fits into a more general incorporation of alignment into | We believe this fits into a more general incorporation of alignment into | 
| 34 | ocp-indent, to replace our internal alignment tool with a syntax-aware one. | ocp-indent, to replace our internal alignment tool with a syntax-aware one. | 
| 35 | We like to align things for readability, like big records, record types, | We like to align things for readability, like big records, record types, | 
| 36 | lists used to build tables, etc. | lists used to build tables, etc. | 
| 37 | ||
| 38 | The proposal also includes indenting "->" in the circumstances below relative | The proposal also includes indenting "->" in the circumstances below relative | 
| 39 | to the enclosing "()", by two spaces. In a sense, this happens first, and | to the enclosing "()", by two spaces. In a sense, this happens first, and | 
| 40 | then the first argument is aligned accordingly. So, there's no manual | then the first argument is aligned accordingly. So, there's no manual | 
| 41 | indentation or spacing below. *) | indentation or spacing below. *) | 
| 42 | ||
| 43 | val instances | val instances | 
| 44 | : unit | : unit | 
| 45 | -> ( Config.Network.t | -> ( Config.Network.t | 
| 46 | ·······->·(App.t·*·Config.instance·*·Config.app)·list | ··········->·(App.t·*·Config.instance·*·Config.app)·list | 
| 47 | ·······->·verbose:bool | ··········->·verbose:bool | 
| 48 | ·······->·'m | ··········->·'m | 
| 49 | , 'm | , 'm | 
| 50 | ) Command.Spec.t | ) Command.Spec.t | 
| 51 | ||
| 52 | val instances | val instances | 
| 53 | : unit | : unit | 
| 54 | -> ( Config.Network.t | -> ( Config.Network.t | 
| 55 | ·······->·(App.t·*·Config.instance·*·Config.app)·list | ··········->·(App.t·*·Config.instance·*·Config.app)·list | 
| 56 | ·······->·verbose:bool·->·'m | ··········->·verbose:bool·->·'m | 
| 57 | , 'm | , 'm | 
| 58 | ) Command.Spec.t | ) Command.Spec.t | 
| 59 | ||
| 60 | (* presumed analog with stars *) | (* presumed analog with stars *) | 
| 61 | val instances : | val instances : | 
| 62 | unit | unit | 
| 63 | * ( Config.Network.t | * ( Config.Network.t | 
| 64 | ······*·(App.t·*·Config.instance·*·Config.app)·list | ········*·(App.t·*·Config.instance·*·Config.app)·list | 
| 65 | ······*·bool | ········*·bool | 
| 66 | ······*·'m | ········*·'m | 
| 67 | , 'm | , 'm | 
| 68 | ) Command.Spec.t | ) Command.Spec.t | 
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | let f x = | let f x = | 
| 1 | stop | stop | 
| 2 | (* We don't do this as a matter of style, but the indentation reveals a common | (* We don't do this as a matter of style, but the indentation reveals a common | 
| 3 | mistake. *) | mistake. *) | 
| 4 | >>> fun () -> don't_wait_for (close fd); | >>> fun () -> don't_wait_for (close fd); | 
| 5 | ················bind·fd | ··bind·fd | 
| 6 | ||
| 7 | let f x = | let f x = | 
| 8 | stop | stop | 
| 9 | (* This is what was intended, which is indented correctly, although it's bad | (* This is what was intended, which is indented correctly, although it's bad | 
| 10 | style on my part. *) | style on my part. *) | 
| 11 | >>> (fun () -> don't_wait_for (close fd)); | >>> (fun () -> don't_wait_for (close fd)); | 
| 12 | bind | bind | 
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | let f x = | let f x = | 
| 1 | (fun x -> x [ (fun () -> 3) ; | (fun x -> x [ (fun () -> 3) ; | 
| 2 | (fun () -> 4) ]) | (fun () -> 4) ]) | 
| 3 | ||
| 4 | let f x = (fun x -> x [ (fun () -> 3) ; | let f x = (fun x -> x [ (fun () -> 3) ; | 
| 5 | (fun () -> 4) ]) | (fun () -> 4) ]) | 
| 6 | ||
| 7 | let f x = | let f x = | 
| 8 | x [ (fun () -> 3) ; | x [ (fun () -> 3) ; | 
| 9 | (fun () -> 4) ] | (fun () -> 4) ] | 
| 10 | ||
| 11 | let f x = | let f x = | 
| 12 | [ (fun () -> 3) ; | [ (fun () -> 3) ; | 
| 13 | (fun () -> 4) ] | (fun () -> 4) ] | 
| 14 | ||
| 15 | let f x = | let f x = | 
| 16 | (fun x -> x [ (fun () -> | (fun x -> x [ (fun () -> | 
| 17 | ···················3)·; | ·······3)·; | 
| 18 | ················(fun·()·->·4)·]) | ·······(fun·()·->·4)·]) | 
| 19 | ||
| 20 | let f x = (fun x -> x [ (fun () -> | let f x = (fun x -> x [ (fun () -> | 
| 21 | ···························3)·; | ····3)·; | 
| 22 | ························(fun·()·->·4)·]) | ····(fun·()·->·4)·]) | 
| 23 | ||
| 24 | let f x = | let f x = | 
| 25 | x [ (fun () -> | x [ (fun () -> | 
| 26 | ·········3)·; | ······3)·; | 
| 27 | (fun () -> 4) ] | (fun () -> 4) ] | 
| 28 | ||
| 29 | let f x = | let f x = | 
| 30 | [ (fun () -> | [ (fun () -> | 
| 31 | ·······3)·; | ········3)·; | 
| 32 | (fun () -> 4) ] | (fun () -> 4) ] | 
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | (** ocaml classes | (** ocaml classes | 
| 1 | (http://caml.inria.fr/pub/docs/manual-ocaml/manual017.html) | (http://caml.inria.fr/pub/docs/manual-ocaml/manual017.html) | 
| 2 | *) | *) | 
| 3 | ||
| 4 | (* class types *) | (* class types *) | 
| 5 | ||
| 6 | class type c = | class type c = | 
| 7 | object | object | 
| 8 | end | end | 
| 9 | ||
| 10 | class type c = | class type c = | 
| 11 | M.cl | M.cl | 
| 12 | ||
| 13 | class type c = | class type c = | 
| 14 | ['a, 'b] M.cl | ['a, 'b] M.cl | 
| 15 | ||
| 16 | class type c = | class type c = | 
| 17 | object | object | 
| 18 |     ('ty) |     ('ty) | 
| 19 | inherit cl | inherit cl | 
| 20 | val mutable virtual | val mutable virtual | 
| 21 | var : bool | var : bool | 
| 22 | method private bar1 x ~y : bool | method private bar1 x ~y : bool | 
| 23 |     method private virtual bar2 : 'a 'b.('a,'b) Hashtbl.t |     method private virtual bar2 : 'a 'b.('a,'b) Hashtbl.t | 
| 24 | constraint | constraint | 
| 25 | 'a = 'b | 'a = 'b | 
| 26 | end | end | 
| 27 | ||
| 28 | (* class expressions *) | (* class expressions *) | 
| 29 | ||
| 30 | class c = | class c = | 
| 31 | ['a, 'b] | ['a, 'b] | 
| 32 | M.cl | M.cl | 
| 33 | ||
| 34 | class c = | class c = | 
| 35 | fun a b -> | fun a b -> | 
| 36 | ····object | ··object | 
| 37 | ····end | ··end | 
| 38 | ||
| 39 | class c = object | class c = object | 
| 40 | val x = true | val x = true | 
| 41 | end | end | 
| 42 | ||
| 43 | class c = | class c = | 
| 44 | object | object | 
| 45 | (_ : | (_ : | 
| 46 | 'a) | 'a) | 
| 47 | inherit Something.someclass | inherit Something.someclass | 
| 48 | as v | as v | 
| 49 | val mutable | val mutable | 
| 50 | var : bool | var : bool | 
| 51 | = true | = true | 
| 52 | val mutable virtual var2 | val mutable virtual var2 | 
| 53 | : string | : string | 
| 54 | method private bar1 x ~y : bool = | method private bar1 x ~y : bool = | 
| 55 | false | false | 
| 56 |     method private virtual bar2 : 'a 'b.('a,'b) Hashtbl.t |     method private virtual bar2 : 'a 'b.('a,'b) Hashtbl.t | 
| 57 | constraint | constraint | 
| 58 | 'a = 'b | 'a = 'b | 
| 59 | initializer | initializer | 
| 60 | z | z | 
| 61 | end | end | 
| 62 | ||
| 63 | (* method specific expressions *) | (* method specific expressions *) | 
| 64 | ||
| 65 | let e = | let e = | 
| 66 | var <- true | var <- true | 
| 67 | ||
| 68 | let e = | let e = | 
| 69 |   {< var = false; |   {< var = false; | 
| 70 | var2 = true; | var2 = true; | 
| 71 | >} | >} | 
| 72 | ||
| 73 | ||
| 74 | (* class definitions *) | (* class definitions *) | 
| 75 | ||
| 76 | class cl = | class cl = | 
| 77 | object | object | 
| 78 | val x = true | val x = true | 
| 79 | end | end | 
| 80 | and | and | 
| 81 | virtual ['a, 'b] | virtual ['a, 'b] | 
| 82 | cl2 x y : | cl2 x y : | 
| 83 | object | object | 
| 84 | val x : bool | val x : bool | 
| 85 | end = fun x y -> | end = fun x y -> | 
| 86 | object | object | 
| 87 | val x : bool = true | val x : bool = true | 
| 88 | end | end | 
| 89 | ||
| 90 | class cl | class cl | 
| 91 | : object end | : object end | 
| 92 | ||
| 93 | class type virtual ['a] clty = object | class type virtual ['a] clty = object | 
| 94 | method x : int | method x : int | 
| 95 | end | end | 
| 96 | ||
| 97 | (* objects *) | (* objects *) | 
| 98 | val a : | val a : | 
| 99 | < > | < > | 
| 100 | let () = () | let () = () | 
| 101 | ||
| 102 | val a : | val a : | 
| 103 | < .. > | < .. > | 
| 104 | let () = () | let () = () | 
| 105 | ||
| 106 | val a : | val a : | 
| 107 | < meth: int option; | < meth: int option; | 
| 108 | meth2: 'a. 'a option; | meth2: 'a. 'a option; | 
| 109 |     meth3: 'a 'b. ('a,'b) Hashtbl.t > |     meth3: 'a 'b. ('a,'b) Hashtbl.t > | 
| 110 | let () = () | let () = () | 
| 111 | ||
| 112 | val a : | val a : | 
| 113 | < meth: int option; | < meth: int option; | 
| 114 | meth2: 'a. 'a option; | meth2: 'a. 'a option; | 
| 115 |     meth3: 'a 'b. ('a,'b) Hashtbl.t; |     meth3: 'a 'b. ('a,'b) Hashtbl.t; | 
| 116 | .. > | .. > | 
| 117 | let () = () | let () = () | 
| 118 | ||
| 119 | (* #-types *) | (* #-types *) | 
| 120 | val a : | val a : | 
| 121 | #M.meth | #M.meth | 
| 122 | ||
| 123 | val a : | val a : | 
| 124 | 'a#M.meth | 'a#M.meth | 
| 125 | ||
| 126 | val a : | val a : | 
| 127 |   ('a,'b*'c) |   ('a,'b*'c) | 
| 128 | #M.meth | #M.meth | 
| 129 | ||
| 130 | (* object types *) | (* object types *) | 
| 131 | type a = | type a = | 
| 132 | < > | < > | 
| 133 | let () = () | let () = () | 
| 134 | ||
| 135 | type a = | type a = | 
| 136 | < .. > | < .. > | 
| 137 | let () = () | let () = () | 
| 138 | ||
| 139 | type a = | type a = | 
| 140 | < meth: int option; | < meth: int option; | 
| 141 | meth2: 'a. 'a option; | meth2: 'a. 'a option; | 
| 142 |     meth3: 'a 'b. ('a,'b) Hashtbl.t > |     meth3: 'a 'b. ('a,'b) Hashtbl.t > | 
| 143 | let () = () | let () = () | 
| 144 | ||
| 145 | type a = | type a = | 
| 146 | < meth: int option; | < meth: int option; | 
| 147 | meth2: 'a. 'a option; | meth2: 'a. 'a option; | 
| 148 |     meth3: 'a 'b. ('a,'b) Hashtbl.t; |     meth3: 'a 'b. ('a,'b) Hashtbl.t; | 
| 149 | .. > | .. > | 
| 150 | let () = () | let () = () | 
| 151 | ||
| 152 | type t = | type t = | 
| 153 | < a : int; b: | < a : int; b: | 
| 154 | < a: int; b: < c:int > > | < a: int; b: < c:int > > | 
| 155 | > | > | 
| 156 | let () = () | let () = () | 
| 157 | ||
| 158 | type t = | type t = | 
| 159 | < a : int; b: | < a : int; b: | 
| 160 | < a: int; b: < c: int -> int> >; | < a: int; b: < c: int -> int> >; | 
| 161 | c: int | c: int | 
| 162 | > | > | 
| 163 | let () = () | let () = () | 
| 164 | ||
| 165 | type 'a t = | type 'a t = | 
| 166 | | Bla : < x : int > t | | Bla : < x : int > t | 
| 167 | | Blo : < y : int > t | | Blo : < y : int > t |