Skip to content

Instantly share code, notes, and snippets.

@m2ym
Created April 8, 2015 09:01
Show Gist options
  • Save m2ym/70475023c03e6d298449 to your computer and use it in GitHub Desktop.
Save m2ym/70475023c03e6d298449 to your computer and use it in GitHub Desktop.
Try to implement Haskell's show in OCaml using ppx_overload
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
Copy link

ghost commented May 6, 2015

Why not use english:(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment