Skip to content

Instantly share code, notes, and snippets.

@ghost-not-in-the-shell
Created January 30, 2019 22:36
Show Gist options
  • Save ghost-not-in-the-shell/8a1f9a755a852135c9210429c8d320ed to your computer and use it in GitHub Desktop.
Save ghost-not-in-the-shell/8a1f9a755a852135c9210429c8d320ed to your computer and use it in GitHub Desktop.
A simple OCaml program using Async
open Core
open Async
let add_all file =
Reader.file_contents file >>= fun contents ->
let ls = String.split_lines contents in
let ss = String.split_on_chars (String.concat ls) ~on:[','] in
let ns = List.map ss ~f:Int.of_string in
let sum = List.fold_left ns ~init:0 ~f:(+) in
printf "%d\n" sum;
return ()
let () =
Command.async_spec
~summary:"Adds it all!"
Command.Spec.(empty +> anon ("file" %: string))
(fun file () -> add_all file)
|> Command.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment