Skip to content

Instantly share code, notes, and snippets.

@avsm
Created April 20, 2026 09:12
Show Gist options
  • Select an option

  • Save avsm/13ae99c41eba9f0c561e28f8f66899b8 to your computer and use it in GitHub Desktop.

Select an option

Save avsm/13ae99c41eba9f0c561e28f8f66899b8 to your computer and use it in GitHub Desktop.
demonstrator of oi with Base/ppx
[@@@opam base stdio ppx_jane]
open Base
open Stdio
type t = { bar: float } [@@deriving sexp]
let rec read_and_accumulate accum =
let line = In_channel.input_line In_channel.stdin in
match line with
| None -> accum
| Some x -> read_and_accumulate (accum +. Float.of_string x)
let () =
let t = { bar=read_and_accumulate 0. } in
printf "Total: %s\n" (Sexp.to_string_hum (sexp_of_t t))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment