Created
January 25, 2016 17:05
-
-
Save Kakadu/4eb426217a49a059364b to your computer and use it in GitHub Desktop.
OCaml 4.02.3 with modular implicits
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 Show = sig | |
type t | |
val show : t -> unit | |
end;; | |
let print {S : Show} x = S.show x;; | |
implicit module Show_float = struct | |
type t = float | |
let show x = Printf.printf "Show_float: %f\n" x | |
end;; | |
module Show_list_impl {X : Show} = struct | |
type t = X.t list | |
let show x = | |
Printf.printf "Show_list: [\n"; | |
List.iter X.show x; | |
Printf.printf "]\n%!" | |
end;; | |
implicit module Show_list = Show_list_impl;; | |
let _ = print [1.;2.5;-3.4];; | |
implicit module Show_int = struct | |
type t = int | |
let show x = Printf.printf "Show_int: %d\n" x | |
end;; | |
let _ = print [3;5;1];; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment