ocaml: phase 5.1 unique_set.ml baseline (Set.Make + IntOrd, count = 9)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
First baseline that exercises the functor pipeline end to end:
module IntOrd = struct
type t = int
let compare a b = a - b
end
module IntSet = Set.Make (IntOrd)
let unique_count xs =
let s = List.fold_left (fun s x -> IntSet.add x s) IntSet.empty xs in
IntSet.cardinal s
Counts unique elements in [3;1;4;1;5;9;2;6;5;3;5;8;9;7;9]:
{1,2,3,4,5,6,7,8,9} -> 9
The input has 15 elements with 9 unique values. The 'type t = int'
declaration in IntOrd is required by real OCaml; OCaml-on-SX is
dynamic and would accept it without, but we include it for source
fidelity. 27 baseline programs total.
This commit is contained in:
@@ -26,5 +26,6 @@
|
||||
"roman.ml": 44,
|
||||
"sieve.ml": 15,
|
||||
"sum_squares.ml": 385,
|
||||
"unique_set.ml": 9,
|
||||
"word_count.ml": 3
|
||||
}
|
||||
|
||||
14
lib/ocaml/baseline/unique_set.ml
Normal file
14
lib/ocaml/baseline/unique_set.ml
Normal file
@@ -0,0 +1,14 @@
|
||||
module IntOrd = struct
|
||||
type t = int
|
||||
let compare a b = a - b
|
||||
end
|
||||
|
||||
module IntSet = Set.Make (IntOrd)
|
||||
|
||||
let unique_count xs =
|
||||
let s = List.fold_left (fun s x -> IntSet.add x s) IntSet.empty xs in
|
||||
IntSet.cardinal s
|
||||
|
||||
;;
|
||||
|
||||
unique_count [3; 1; 4; 1; 5; 9; 2; 6; 5; 3; 5; 8; 9; 7; 9]
|
||||
Reference in New Issue
Block a user