Skip to content

Commit 10117ca

Browse files
committed
Rune dune fmt
1 parent b816a89 commit 10117ca

File tree

13 files changed

+116
-118
lines changed

13 files changed

+116
-118
lines changed

example/boolean.ml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@ let true_lambda = typed_term (Const "True")
66
let false_lambda = typed_term (Const "False")
77
let bool_type = type_union [ true_lambda.rtype; false_lambda.rtype ]
88
let unary_bool_op = func_type (bool_type.union, bool_type.union)
9-
10-
let binary_bool_op =
11-
func_type (bool_type.union, unary_bool_op.union)
12-
13-
let ternary_bool_op =
14-
func_type (bool_type.union, binary_bool_op.union)
15-
16-
let identity_lambda =
17-
typed_term (Abstraction [ (bool_type, Variable 0) ])
9+
let binary_bool_op = func_type (bool_type.union, unary_bool_op.union)
10+
let ternary_bool_op = func_type (bool_type.union, binary_bool_op.union)
11+
let identity_lambda = typed_term (Abstraction [ (bool_type, Variable 0) ])
1812

1913
let not_lambda =
2014
typed_term

example/exampleHelpers.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ let build_fix (arg_type : recursive_type) (return_type : recursive_type) =
9696
fix
9797

9898
(* Fixes a provided abstraction with the given arg and return type *)
99-
let fix (arg_type : recursive_type) (return_type : recursive_type)
100-
(term : term) =
99+
let fix (arg_type : recursive_type) (return_type : recursive_type) (term : term)
100+
=
101101
let fix_term = build_fix arg_type return_type in
102102
Application (fix_term.term, term)

src/common/helpers.ml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,27 @@ let opt_list_to_list_opt (input : 'a option list) : 'a list option =
3434

3535
type 'a tuple = 'a list
3636

37-
let rec multi_list_product (nested_list: 'a list tuple): 'a tuple list =
38-
let rec helper (acc: 'a tuple list) (l1: 'a list) (l2: 'a list tuple) =
39-
match l1, l2 with
37+
let rec multi_list_product (nested_list : 'a list tuple) : 'a tuple list =
38+
let rec helper (acc : 'a tuple list) (l1 : 'a list) (l2 : 'a list tuple) =
39+
match (l1, l2) with
4040
| [], _ | _, [] -> acc
41-
| h1::t1, h2::t2 ->
42-
let acc = (h1::h2)::acc in
43-
let acc = helper acc t1 l2 in
44-
helper acc [ h1 ] t2
45-
in match nested_list with
41+
| h1 :: t1, h2 :: t2 ->
42+
let acc = (h1 :: h2) :: acc in
43+
let acc = helper acc t1 l2 in
44+
helper acc [ h1 ] t2
45+
in
46+
match nested_list with
4647
| [] -> []
47-
| [l1] -> List.map (fun x -> [x]) l1
48-
| l1::tail ->
49-
let tail_product = multi_list_product tail in
50-
helper [] l1 tail_product
48+
| [ l1 ] -> List.map (fun x -> [ x ]) l1
49+
| l1 :: tail ->
50+
let tail_product = multi_list_product tail in
51+
helper [] l1 tail_product
5152

52-
let short_circuit_and (exp1: unit -> bool) (exp2: unit -> bool) =
53+
let short_circuit_and (exp1 : unit -> bool) (exp2 : unit -> bool) =
5354
if exp1 () then exp2 () else false
5455

55-
let short_circuit_or (exp1: unit -> bool) (exp2: unit -> bool) =
56-
if exp1() then true else exp2 ()
56+
let short_circuit_or (exp1 : unit -> bool) (exp2 : unit -> bool) =
57+
if exp1 () then true else exp2 ()
5758

58-
let map_pair (func: 'a -> 'b) (first, second: 'a * 'a): 'b * 'b =
59-
(func first), (func second)
59+
let map_pair (func : 'a -> 'b) ((first, second) : 'a * 'a) : 'b * 'b =
60+
(func first, func second)

src/dune

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
(library
22
(name setTypedLambda)
3-
(libraries metatypes termTypes typeOperations termOperations common stringUtils))
3+
(libraries
4+
metatypes
5+
termTypes
6+
typeOperations
7+
termOperations
8+
common
9+
stringUtils))

src/stringUtils/stringUtils.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ let rec term_to_string (term : term) =
6363
| UnivQuantifier inner_term ->
6464
Printf.sprintf "\\T.{%s}" (term_to_string inner_term)
6565
| UnivApplication (inner_term, inner_type) ->
66-
Printf.sprintf "(%s) [%s]" (term_to_string inner_term) (type_to_string inner_type)
66+
Printf.sprintf "(%s) [%s]"
67+
(term_to_string inner_term)
68+
(type_to_string inner_type)
6769

6870
and branch_to_string (branch_type, branch_body) =
6971
Printf.sprintf "%s:%s"

src/termOperations/substituteUnivVar.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ open TypeOperations.SubstituteUnivVar
77

88
(* Substitutes the [with_type] into the [in_term] for universal type variables referencing
99
the universal quantification at this level (0, or higher if nested within another universal quantifications) *)
10-
let rec substitute_univ_var_term (with_type : recursive_type) (in_term : term)
11-
: term =
10+
let rec substitute_univ_var_term (with_type : recursive_type) (in_term : term) :
11+
term =
1212
(* Shift the universal type indices in the argument by one since it is about to be substituted into a universal quantification,
1313
where their binding quantification is one further away *)
1414
let shifted_with_type = shift_univ_var_type with_type 1 in

src/termOperations/valToTerm.ml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,15 @@ and substitute_in_term (term : term) (env : environment) (depth : int) =
3737
| Application (left_term, right_term) ->
3838
Application
3939
( substitute_in_term left_term env depth,
40-
substitute_in_term right_term env depth)
40+
substitute_in_term right_term env depth )
4141
(* If a variable references a free variable, we pull it from the env, otherwise, leave it
4242
because it references a bound variable within this abstraction *)
4343
| Variable num ->
4444
if num - depth < 0 then Variable num
4545
else value_to_term (List.nth env (num - depth))
4646
(* Universal quantifiers are substituted recursively *)
4747
| UnivQuantifier inner_term ->
48-
UnivQuantifier (substitute_in_term inner_term env depth)
48+
UnivQuantifier (substitute_in_term inner_term env depth)
4949
(* Universal application requires a substitution in the term, but leaves the type the same *)
5050
| UnivApplication (inner_term, inner_type) ->
51-
UnivApplication
52-
( substitute_in_term inner_term env depth,
53-
inner_type)
51+
UnivApplication (substitute_in_term inner_term env depth, inner_type)

src/typeOperations/context.ml

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ let get_type_in_context (t : recursive_type)
4444
build_recursive_type new_union (recursive_context @ new_context)
4545

4646
(* Converts a pair of recursive types into a pair of union types that share a context *)
47-
let get_unified_type_context_pair (typea: recursive_type) (typeb: recursive_type) =
47+
let get_unified_type_context_pair (typea : recursive_type)
48+
(typeb : recursive_type) =
4849
let recontextualized_typeb = get_type_in_context typeb typea.context in
4950
let new_typeb = recontextualized_typeb.union in
5051
((typea.union, new_typeb), recontextualized_typeb.context)
@@ -55,30 +56,47 @@ let get_unified_type_context (types : recursive_type list) =
5556
let new_unions_rev, new_context =
5657
List.fold_left
5758
(fun (acc_union, acc_context) next_type ->
58-
let recontextualized_next_union = get_type_in_context next_type acc_context in
59+
let recontextualized_next_union =
60+
get_type_in_context next_type acc_context
61+
in
5962
let new_acc_union = recontextualized_next_union.union :: acc_union in
6063
let new_acc_context = recontextualized_next_union.context in
6164
(new_acc_union, new_acc_context))
62-
([], []) types in
65+
([], []) types
66+
in
6367
(* We must reverse the list of unions since we fold left but want to keep the types in the right order *)
6468
let new_unions = List.rev new_unions_rev in
65-
new_unions, new_context
69+
(new_unions, new_context)
6670

6771
(* TODO: consider writing more dedicated logic for this rather than the showving intermediate into intersection *)
6872
(* Takes a list of arg types and their corresponding body types, and joined them into
6973
a single recursive type for the intersection of the functions *)
70-
let unify_function_types (arg_types: recursive_type list) (body_types: recursive_type list) =
74+
let unify_function_types (arg_types : recursive_type list)
75+
(body_types : recursive_type list) =
7176
(* First, build individual unary function types for each arg/body pair *)
72-
let unary_types = List.map2 (fun arg_type body_type ->
73-
let (new_arg_type, new_body_type), new_context = get_unified_type_context_pair arg_type body_type in
74-
build_recursive_type [ Intersection [(new_arg_type, new_body_type )]] new_context
75-
) arg_types body_types in
77+
let unary_types =
78+
List.map2
79+
(fun arg_type body_type ->
80+
let (new_arg_type, new_body_type), new_context =
81+
get_unified_type_context_pair arg_type body_type
82+
in
83+
build_recursive_type
84+
[ Intersection [ (new_arg_type, new_body_type) ] ]
85+
new_context)
86+
arg_types body_types
87+
in
7688
(* Then, rectonextualize all of them so we can prepare to join them into a single type *)
7789
let new_unary_unions, new_context = get_unified_type_context unary_types in
7890
(* Then destructure all of the unary types to build a single intersection type *)
79-
let unary_list = List.fold_left (fun acc_func_types next_union ->
80-
match next_union with
81-
| [ Intersection [ next_unary ]] -> next_unary::acc_func_types
82-
| _ -> raise (Failure "there was a problem destructuring the unary function types")
83-
) [] new_unary_unions in
84-
build_recursive_type [ Intersection unary_list ] new_context
91+
let unary_list =
92+
List.fold_left
93+
(fun acc_func_types next_union ->
94+
match next_union with
95+
| [ Intersection [ next_unary ] ] -> next_unary :: acc_func_types
96+
| _ ->
97+
raise
98+
(Failure
99+
"there was a problem destructuring the unary function types"))
100+
[] new_unary_unions
101+
in
102+
build_recursive_type [ Intersection unary_list ] new_context

src/typeOperations/shiftUnivVar.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,4 @@ and shift_univ_var_base (shift_amount : int) (cutoff : int) (base : base_type) =
9191

9292
and shift_univ_var_func (shift_amount : int) (cutoff : int)
9393
((arg, return) : unary_function) =
94-
map_pair (shift_univ_var_union shift_amount cutoff) (arg, return)
94+
map_pair (shift_univ_var_union shift_amount cutoff) (arg, return)

src/typeOperations/substituteUnivVar.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ let rec substitute_univ_var_type (with_type : recursive_type)
4949
with the with_type, respecting free variables and the complexities of recursive
5050
types *)
5151
and substitute_univ_var_type_rec (variable_num : int)
52-
(with_type : recursive_type) (in_type : recursive_type) : recursive_type
53-
=
52+
(with_type : recursive_type) (in_type : recursive_type) : recursive_type =
5453
(* Perform initial pass over substitution to get information we use to safely perform substitution *)
5554
let substitution_profile = get_substitution_profile variable_num in_type in
5655

@@ -343,4 +342,4 @@ and merge_context_subs_binary (directives_a : context_subs)
343342
| Some x, Some _ -> Some x
344343
| None, y -> y
345344
| x, None -> x)
346-
directives_a directives_b
345+
directives_a directives_b

0 commit comments

Comments
 (0)