caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] [ANN] ppx_overload : ppx for user definable SML style overloading
@ 2014-10-13 13:49 Jun Furuse
  2014-10-13 13:56 ` Peter Zotov
  0 siblings, 1 reply; 5+ messages in thread
From: Jun Furuse @ 2014-10-13 13:49 UTC (permalink / raw)
  To: caml-list

Hi,

I have OPAM-released ppx_overload, a ppx for user definable SML style
overloading.

For example you can overload (+) and (+.) to Plus.(+) as follows:

module Plus = struct
  external (+) : 'a -> 'a -> 'a = "%OVERLOADED"
  module Int = struct
    let (+) = Pervasives.(+)
  end
  module Float = struct
    let (+) = Pervasives.(+.)
  end
end

Then Plus.(+) works for int and float additions!

It works as follows:

* Declaration of overloaded values by external "%OVERLOADED"
* List the instances with the same name in its sub modules.
* The uses of overloaded values are resolved to one of their instances
at typing phase.

The overloading of ppx_overload is pretty limited: you cannot derive
overloading by using overloaded values polymorphicially. You cannot
define overloaded double with the overloaded Plus.(+). But still it is
a very interesting ppx example to combine with the OCaml typing.

ppx_overload is now available in OPAM. More detailed explanation how
it works is explained in the project page:
https://bitbucket.org/camlspotter/compiler-libs-hack . Enjoy!

Thanks
Jun

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-10-14 14:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-13 13:49 [Caml-list] [ANN] ppx_overload : ppx for user definable SML style overloading Jun Furuse
2014-10-13 13:56 ` Peter Zotov
2014-10-13 14:54   ` Alain Frisch
2014-10-14 13:08     ` Jun Furuse
2014-10-14 14:55       ` Peter Zotov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).