Refunctionalizing an integer?

Posted on October 19, 2025 First imagine that the OCaml type int is infinite. Now what happens when you refunctionalize an infinite datatype? Let make a concrete program to work with. This will be a stateful generator that outputs the integers, starting at 0 , and ending at an exclusive limit n . type 'a gen = { next : unit -> 'a option } let range n = let r = ref 0 in { next = fun () -> let i =…