@@ -254,6 +254,23 @@ let binary_bool_list_op =
254
254
[ Intersection [ (binary_poly_bool, binary_list_bool) ] ])
255
255
binary_poly_bool_op binary_list_bool_op
256
256
257
+ (* Represents `X -> Bool`, the first part of the find function *)
258
+ let poly_bool_op = func_type ([ UnivTypeVar 0 ], bool_type.union)
259
+
260
+ (* Represents `X List -> X | None`, the second half of the find function *)
261
+ let list_extract_op =
262
+ map_type
263
+ (fun list ->
264
+ [ Intersection [ (list , UnivTypeVar 0 :: none_label.stype.union) ] ])
265
+ polymoprhic_list_type.full
266
+
267
+ (* Represents `(X -> Bool) -> X List -> X | None`, the type of the find function *)
268
+ let find_op =
269
+ map_type2
270
+ (fun poly_bool list_extract ->
271
+ [ Intersection [ (poly_bool, list_extract) ] ])
272
+ poly_bool_op list_extract_op
273
+
257
274
(* Polymoprhic function that prepends an element of arbitrary tpye to a list of that type *)
258
275
let cons =
259
276
typed_term
@@ -328,6 +345,7 @@ let fix_map =
328
345
fix (func_type ([ UnivTypeVar 1 ], [ UnivTypeVar 0 ])) list_transform_op
329
346
330
347
let fix_equal = fix binary_poly_bool_op binary_list_bool_op
348
+ let fix_find = fix poly_bool_op list_extract_op
331
349
332
350
let length =
333
351
typed_term
@@ -621,8 +639,39 @@ let equal =
621
639
] );
622
640
])))
623
641
642
+ let find =
643
+ typed_term
644
+ (UnivQuantifier
645
+ (fix_find
646
+ (Abstraction
647
+ [
648
+ ( find_op,
649
+ Abstraction
650
+ [
651
+ ( poly_bool_op,
652
+ Abstraction
653
+ [
654
+ (empty_list.stype, none_label.term);
655
+ ( polymoprhic_list_type.non_empty,
656
+ Application
657
+ ( Abstraction
658
+ [
659
+ ( true_lambda.stype,
660
+ Application (head_poly.term, Variable 1 )
661
+ );
662
+ ( false_lambda.stype,
663
+ binary_apply (Variable 3 ) (Variable 2 )
664
+ (Application
665
+ (tail_poly.term, Variable 1 )) );
666
+ ],
667
+ Application
668
+ ( Variable 1 ,
669
+ Application (head_poly.term, Variable 0 ) )
670
+ ) );
671
+ ] );
672
+ ] );
673
+ ])))
674
+
624
675
(* List functions we should implement:
625
- * equal
626
- * find (return element and/or index)
627
676
* flatten
628
677
*)
0 commit comments