Created
January 30, 2019 22:36
-
-
Save ghost-not-in-the-shell/8a1f9a755a852135c9210429c8d320ed to your computer and use it in GitHub Desktop.
A simple OCaml program using Async
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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