Created
April 8, 2015 09:01
-
-
Save m2ym/70475023c03e6d298449 to your computer and use it in GitHub Desktop.
Try to implement Haskell's show in OCaml using ppx_overload
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 | |
val show : 'a -> string | |
end | |
module Show = struct | |
external show : 'a -> string = "%OVERLOADED" | |
module Int = struct | |
let show = string_of_int | |
end | |
module Float = struct | |
let show = string_of_float | |
end | |
(* too ambiguous *) | |
module Tuple2 = struct | |
let show (a, b) = show a ^ ", " ^ show b | |
end | |
(* functor? *) | |
module Tuple2 (A : Show) (B : Show) = struct | |
let show (a, b) = A.show a ^ ", " ^ B.show b | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why not use english:(