let primes =
let open Seq in
let rec sieve p =
let (p, xs) = from_option (lazy (error "wasn't infinite")) (uncons p)
p :> lazy (xs |> filter ((> 0) % flip mod p) |> sieve)
sieve (arithmetic_seq 2 3)
let factor i =
let rec go acc primes i =
match i, Seq.uncons primes with
| 1, _ -> acc
| p, None -> p :: acc
| i, Some (p, _) when i `mod` p == 0 ->
go (p :: acc) primes (i // p)
| i, Some (_, ps) -> go acc ps i
go [] (primes |> Seq.take_while (fun p -> p <= int_of_float (i / 2))) i