假设我们已经有啤酒与威士忌两个模块:
module Beer = struct
type t = BEER
let pour () =
let () = Printf.printf "... a nice head ... " in BEER
let consume t = Printf.printf "Ha! Nothing like a good beer to quench the thirst\n"
end
module Whisky = struct
type t = WHISKY
let pour () =
let () = Printf.printf "... 2 fingers of this ...." in WHISKY
let consume _ = Printf.printf "... Ha! Piss of the Gods!\n"
使用OCaml的Functor与First class module
最新推荐文章于 2020-11-25 21:25:33 发布