Created
April 11, 2015 16:11
-
-
Save podhmo/f495c1b1a0fa02e6b5be to your computer and use it in GitHub Desktop.
This file contains 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_kernel.Std | |
module type Itemize = sig | |
val dump : string list -> string | |
end | |
module HTML : Itemize = struct | |
let dump xs = | |
let buf = Buffer.create 0 in | |
let put_item x = | |
Buffer.add_string buf "<li>"; | |
Buffer.add_string buf x; | |
Buffer.add_string buf "<li>"; | |
in | |
Buffer.add_string buf "<ul>"; | |
List.iter xs ~f:put_item; | |
Buffer.add_string buf "</ul>"; | |
Buffer.contents buf | |
end | |
module Text : Itemize = struct | |
let dump xs = | |
let buf = Buffer.create 0 in | |
let put_item x = | |
Buffer.add_string buf "- "; | |
Buffer.add_string buf x; | |
Buffer.add_string buf "\n"; | |
in | |
List.iter xs ~f:put_item; | |
Buffer.contents buf | |
end | |
let printer title content ((module M): (module Itemize)) = | |
Printf.printf "** %s **\n" (title); | |
print_string @@ M.dump content | |
let main title flag = | |
let xs = ["foo"; "bar"; "boo";] in | |
match flag with | |
| "html" | "HTML" -> printer title xs (module HTML) | |
| _ -> printer title xs (module Text) | |
let () = | |
main Sys.argv.(1) Sys.argv.(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment