Created
October 15, 2018 08:18
-
-
Save zerobias/a1a7065894287c3ade0d9f52ab271c40 to your computer and use it in GitHub Desktop.
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
module type DEVICE = { | |
let draw: string => unit; | |
}; | |
let devices: Hashtbl.t(string, module DEVICE) = Hashtbl.create(17); | |
module SVG = { | |
let draw = string => Js.log2("svg module", string); | |
}; | |
Hashtbl.add(devices, "SVG", (module SVG): (module DEVICE)); | |
module PDF = { | |
let draw = string => Js.log2("pdf module", string); | |
}; | |
Hashtbl.add(devices, "PDF", (module PDF): (module DEVICE)); | |
exception E; | |
module Device = ( | |
val try (Hashtbl.find(devices, "PDF")) { | |
| Not_found => | |
Js.log("Unknown device %s\n"); | |
raise(E); | |
}: | |
DEVICE | |
); | |
let draw_using_device = (device_name, picture) => { | |
module Device = (val Hashtbl.find(devices, device_name): DEVICE); | |
Device.draw(picture); | |
}; | |
Js.log(devices); | |
draw_using_device("PDF", "+_+") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment